Quote Originally Posted by Bruce View Post
While the PIC is sleeping Timer0 will be off since on-chip clocks are shut down. You could
use Timer1, but you would need an extermal clock during sleep.

If it will be awake during your 5 minute time period, you could use the compare module set
to reset Timer1 on each match. Load CCPR1L and CCPR1H with 62,500, set a prescaler of
1:16, and it will interrupt every 500mS + automatically reset Timer1 to 0.

Then you can just increment a variable in your int handler until your delay period is reached.
This is a lot easier than reloading a timer in an int handler - or fiddling with adjustments to
reload values compensating for code overhead.
You pointed out something I just read this afternoon: timer0 is frozen, which is a problem as I use "@ SLEEP" !!
Well, my idea is to use the folowing parameters:
With a TMR0 preset to 176 and a prescaler of 256 it will interrupt every 10ms.
When in my lasergame program player health points drop below 0, it sets a variable (BIT) called CRITICAL to 1 and enable TMR0 interrupts.
The routine handling the TMR0 interrupt would increment a counter variable and then it would go back to my main loop and... uh... go to sleep, disabling the timer...
But, if I write (preseting CRITICAL to 0):

(program starts here)
loop:
if (countdown == 1) THEN
PAUSEus 15 'shortest pause I can use with a 8MHz clock
ELSE
@ SLEEP
ENDIF
Goto loop


Then when my countdown in the INT handler reaches the desired value, I disable the INT for TMR0 and set CRITICAL to 0 so the main loop will behave as it should: have a sleep when the INT handler has been processed.
My question is: when sleeping, the interrupt will be handled then MCU will go back to "goto loop" or will it continue the "@ sleep"?????