User manual

Table Of Contents
General Purpose Input/Output Labs
© 2009 Microchip Technology Inc. DS41369A-page 31
EQUATION 3-4: MAXIMUM TMR0 OVERFLOW PERIOD
Therefore, to implement delays greater than 65.5mS, a counter variable is
implemented as shown in the flowchart of Figure 3-14 for a 1 second delay.
FIGURE 3-14: DELAY_1S() USING TIMER0
TMR0 Overflow Period = (4/FOSC) x 256 x prescaler
using a maximum prescaler setting of 1:256 and the 4MHz internal oscillator
TMR0 Overflow Period = 1 μS x 256 x 256 = 65.5mS
Delay_1S()
END
YES
NO
counter variable value determined as follows:
1 second/65.5mS = 15.25 or rounded down to 15
Create an 8-bit variable counter and
initialize to 0
Clear the TMR0 register
Clear the TMR0 overflow flag
(T0IF)
T0IF = 0?
counter < or = 15?
Increment counter value by 1
NO
YES