The "generic" way is to
Figure out the maximum "length" of the timers (use Mr. E's Multi-Calc).
Pick an appropriate timer and prescaler.
Figure out what the pre-load count should be for the time interval you need based on the timer, prescaler and oscillator.
The counter will increment from the pre-load value and when it reaches maximum count (0xFFFF for a 16 bit counter), it will set the timer's overflow flag bit (INTCON.2 in the case of TMR0).
So to intialize:
Load the counter with the pre-load count
clear the timer overflow flag bit
enable the timer
Then --
Code:
Top_Of_Main_program:
do some stuff here
IF INTCON.2 THEN ; the bit is set, so overflow has occurred.
TMR0H = HighByte of preload value
TMR0L = LowByte of preload value ; the order is important!
INTCON.2 = 0 ; Clear the flag bit
;Do what you want here when the timeout value is reached.
ENDIF
Goto Top_Of_Main_program
Bookmarks