int0_wakeup.c - uses INT0 to wake from sleep mode.ΒΆ
/Demonstrates the use of int0 interrupt to wake from Sleep mode. Pushbutton on an int0 pin is used to wake from Sleep mode.
#include "pic24_all.h"
/// Interrupt Service Routine for INT0
void _ISRFAST _INT0Interrupt (void) {
_INT0IF = 0; //clear the interrupt bit
}
/// Switch1 configuration, RB7 shares INT0 pin on PIC24HGP202
inline void CONFIG_SW1() {
CONFIG_RB7_AS_DIG_INPUT(); //use RB7 for switch input
ENABLE_RB7_PULLUP(); //enable the pullup
}
int main (void) {
configBasic(HELLO_MSG);
/** Configure the switch ***********/
CONFIG_SW1(); //enables individual CN interrupt also
/** Configure INT0 interrupt */
_INT0IF = 0; //Clear the interrupt flag
_INT0IP = 2; //Choose a priority
_INT0EP = 1; //negative edge triggerred
_INT0IE = 1; //enable INT0 interrupt
while (1) {
outString("Entering Sleep mode, press button to wake.\n");
Finish sending characters before sleeping
WAIT_UNTIL_TRANSMIT_COMPLETE_UART1();
SLEEP(); //macro for asm("pwrsav #0")
}
}