int1_wakeup.c - Uses INT1 to wake from sleep mode.ΒΆ
Demonstrates the use of int1 interrupt to wake from Sleep mode. A pushbutton on a int1 pin is used to wake from Sleep mode.
 
#include "pic24_all.h"
 
Interrupt Service Routine for INT1
void _ISR _INT1Interrupt(void) {
  _INT1IF = 0;    //clear the interrupt bit
}
 
Pushbutton configuration, uses RB13.
void config_pb(void) {
  CONFIG_RB13_AS_DIG_INPUT();
  ENABLE_RB13_PULLUP();
Wait for pull-up to take effect.
  DELAY_US(1);
}
int main(void) {
  configBasic(HELLO_MSG);
  config_pb();
 
Configure INT1 interrupt.
  CONFIG_INT1_TO_RP(RB13_RP);
  _INT1IF = 0;     //Clear the interrupt flag
  _INT1IP = 2;     //Choose a priority
  _INT1EP = 1;     //negative edge triggerred
  _INT1IE = 1;     //enable INT1 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")
  }
}