change_wakeup.c - wake from sleep using a change notification interruptΒΆ
Demonstrates the use of change notification interrupt to wake from Sleep mode. A pushbutton on a change notfication pin will be used to wake the from Sleep mode.
#include "pic24_all.h"
Interrupt Service Routine for Change Notification
void _ISRFAST _CNInterrupt(void) {
Clear the change notification interrupt bit.
_CNIF = 0;
}
Pushbutton configuration: assumes PB is on RB13.
void config_pb(void) {
CONFIG_RB13_AS_DIG_INPUT();
ENABLE_RB13_PULLUP();
ENABLE_RB13_CN_INTERRUPT();
Wait for pull-up to take effect.
DELAY_US(1);
}
int main(void) {
configBasic(HELLO_MSG);
/** Configure the switch ***********/
config_pb(); //enables individual CN interrupt also
/** Configure Change Notification general interrupt */
_CNIF = 0; //Clear the interrupt flag
_CNIP = 2; //Choose a priority > 0
_CNIE = 1; //enable the Change Notification general 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")
}
}