>> but where does the program execution actually continue in the code? Does it always execute the line following the @ SLEEP command?
If wake up by WDT or RA2 then it will always execute the line following the sleep command
>> Can I write to the GIE bit?
whether high or low, it will always execute the line after the sleep command. The difference is if it is low, the program will continue on after the line after the sleep command. If GIE is high and the INTE bit is set, the program will go to the interrupt vector after completing the line after the sleep command. You can set the GIE bit like this
INTCON.7 = 1 ' GIE = 1
You can set the INTE bit like this
INTCON.4 = 1
>> If I have the WDT running (as a fail safe if the external resonator goes out) - will the pic wake from sleep after each WDT cycle?
YES
>> Is there anything special I need to do with the WDT to make sure it doesn't wake the pic?
TURN IT OFF
>> Section 12.4.1 in the datasheet talks about this interrupt on RA2/INT. It notes the INTF bit of INTCON is set when the valid edge appears, the interrupt can be disabled by clearing the INTE bit of INTCON (which I don't think I want in this case). It then says the INTF bit must be cleared before re-enabling the interrupt, and it sounds like I'd need to re-set the INTE bit prior to the next sleep cycle also.
YES (you need to clear it, not re-set it)
Can anyone extrapolate a list of the flags I need to set or clear before executing @SLEEP so that pic will goto sleep, and stay sleeping forever (days, months, years, etc) until that button is pressed driving RA2 high again? And to make the program resume right after the @SLEEP without jumping to some other place as a result of the interrupt?
(Configure WDT off)
PORTA = 0 ; PortA low
ANSEL = 0 ; PortA digital
TRISA = 4 ; RA2 = input
INTCON.7 = 0 ; turn off global interrupts
OPTION_REG.6 = 1 ; wake on rising edge
Code Here
INTCON.1 = 0 ; clear RA2 interrupt flag in case set (right before @ Sleep command)
@ SLEEP
continues here when RA2 goes high (unless goto or branch, etc)
and then here (unless goto or branch etc)
and then here (unless goto or branch etc)
EDIT:
if you have your heart set on using the WDT, you can test bit 4 of the OPTION register to see what woke the PIC from sleep. If this bit is zero, you can put the PIC immediately back to sleep. The danger is you might miss the RA2 high while testing the Option bit (if RA2's high duration is short).
Last edited by paul borgmeier; - 8th January 2008 at 07:29.
Reason: Info on WDT
Paul Borgmeier
Salt Lake City, UT
USA
__________________
Bookmarks