LPC Demo Board Lessons
3.2.9
Lesson 9: Timer0
Timer0 is a counter implemented in the processor. It may be used to count processor
clock cycles or external events. Lesson 9 configures it to count instruction cycles and
set a flag when it rolls over. This frees up the processor to do meaningful work rather
than just wasting cycles.
Timer0 is an 8-bit counter with an optional prescaler, which is configured to divide by
256 before reaching the Timer0 counter.
FIGURE 3-7:
TIMER0 SIMPLIFIED
Clock/4 or
T0CKI pin
Prescaler
Prescaler may be configured
to divide by 2, 4, 8, 16, 32, 64,
128 or 256.
TMR0
T0IF
Flag set when
TMR0 overflows.
Must be cleared
in software.
Note:
See PIC16F690 Timer0 section for more details.
TMR0 is a Special Function Register (SFR) and may be read or modified by the
program. The Prescaler is not a SFR and thus cannot be read or modified by the
program. However, writing to TMR0 clears the Prescaler.
The timer may be fed either by the same clock that drives the processor or by an
external event. Driven by the processor clock, it increments once for every instruction
cycle. This is a convenient method of marking time, better than delay loops, as it allows
the processor to work on the problem rather than waste cycles in delay loops.
The prescaler is configured through the OPTION_REG, see Figure 3-8.
FIGURE 3-8:
PRESCALER CONFIGURATION THROUGH OPTION_REG
X
X
T0CS
T0SE
PSA
PS2
PS1
PS0
bit 7
Legend:
X:
Don’t cares – not Timer0 related.
bit 0
T0CS: Timer0 Clock Source 0 for Instruction Clock.
T0SE: Timer0 Source Edge – Don’t care when connected to instruction clock.
PSA:
PS:
Prescaler Assignment 0 assigns to Timer0.
Prescaler rate select ‘111’ – full prescaler, divide by 256.
Lesson 9 configures Timer0 with the Prescaler for a maximum delay on Timer0. The
prescaler will divide the processor clock by 256 and Timer0 will divide that by 256
again. Thus, Timer0 Flag will be set every 65536 μ s (0.0000001 second * 256 * 256),
or about 15 times a second. The main program sits in a loop waiting for the rollover and
when it does, it increments the display and then loops back.
? 2005 Microchip Technology Inc.
DS51556A-page 27
相关PDF资料
DM164120-3 BOARD DEMO PICKIT2 28-PIN
DM164120-5 BOARD DEMO PICKIT 2 64/80-PIN
DM164123 KIT MANAGEMENT SYSTEM PICDEM
DM180021 KIT STARTER MPLAB FOR PIC18F MCU
DM183022 BOARD DEMO PIC18FXX22 64/80TQFP
DM183032 BOARD EXPLORER PICDEM PIC18
DM240001 BOARD DEMO PIC24/DSPIC33/PIC32
DM240002 BOARD DEV EXPLORER 16 44-PIN
相关代理商/技术参数
DM164120-1 制造商:Microchip Technology Inc 功能描述:DEVELOPMENT TOOLS - PICKIT 2 LOW PIN COU
DM164120-2 功能描述:开发板和工具包 - PIC / DSPIC PICkit 2 44-Pin Count Demo Brd RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压:
DM164120-3 功能描述:开发板和工具包 - PIC / DSPIC PICkit 2 Count Demo Board RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压:
DM164120-4 功能描述:开发板和工具包 - PIC / DSPIC PICkit 2 1 Dem Board RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压:
DM164120-4 制造商:Microchip Technology Inc 功能描述:PICkit 2 18-Pin Demo Board
DM164120-4/16F1827/PG164130 制造商:Microchip Technology Inc 功能描述:PICKIT PIC16F648A DEMO BOARD 制造商:Microchip Technology Inc 功能描述:KIT STARTER 18PIN F1 ENHANCED CORE 制造商:Microchip Technology Inc 功能描述:PICKIT, PIC16F648A, DEMO BOARD 制造商:Microchip Technology Inc 功能描述:PICKIT, PIC16F648A, 18 PIN, DEMO BOARD; Silicon Manufacturer:Microchip; Core Architecture:PIC; Core Sub-Architecture:PIC16; Silicon Core Number:PIC16F; Silicon Family Name:PIC16F18xx; Kit Contents:Demo Board, 2x Bare PCB Boards
DM164120-5 功能描述:开发板和工具包 - PIC / DSPIC PICkit 2 64 demoBoard RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压:
DM164123 功能描述:开发板和工具包 - PIC / DSPIC PICDEM Sys Mgmt Board RoHS:否 制造商:Microchip Technology 产品:Starter Kits 工具用于评估:chipKIT 核心:Uno32 接口类型: 工作电源电压: