Hi,
Even if you are not using interrupts the timer0 rollover (INTCON.2, T0IF) gets set. So you can periodically check if the flag is set. To get proper timeout your main body loop should not execute for more than the timer0 rollover period. Even if it does then you miss a few ticks but still get some dirty timing. So here is how it goes
Code:
OPTION_REG = %11000111 ' SET PRESCALE HERE 256 (Datasheet PAGE 14)
' @4MHz AND PRESCALE TIMER0 ROLLSOVER IN ABOUT 65.5 mS
TIME_COUNTER VAR WORD ' MAY BE A BYTE ALSO
INTCON = 0
TIME_COUNTER = 0
MAIN_LOOP:
' DO WHATEVER
IF INTCON.2 = 1 THEN ' CHECK IF TIMER ROLLED OVER
INTCON.2 = 0 ' CLEAR THE HARDWARE FLAG
TMR0 = 0 ' CLEAR TIMER0 IF YOU WISH
TIME_COUNTER = TIME_COUNTER + 1 ' INCREMENT YOUR COUNTER
ENDIF
IF TIME_COUNTER > PRESET THEN QUIT_LOOP
GOTO MAIN_LOOP
QUIT_LOOP:
' TIME OVER DO WHATEVER
PRESET is hard coded. In your main routine when you receive a valid signal don't forget to clear (Reset) the timer_counter variable and any pending ticks i.e., INTCON.2
Hope this helps
Bookmarks