Test 8. Waking the device from SLEEP with RB4 interrupt-on- change
Program description
Four PORTB pins, RB<7:4>, if configured as inputs, have an interrupt-on-change feature. This interrupt sets flag bit RBIF and can wake the device from SLEEP. Interrupt is enabled after setting the RBIE mask:
bsf intcon, rbie
Interrupt on mismatch feature together with software configurable pull-upps on these pins allow easy interface to a switch and make it possible for wake up on switch depression.
After sleep instruction the device enters the sleep mode and waits for interrupt to be waked up.
If the interrupt is enabled by the associated Interrupt mask IE and the GIE bit is not set, it can wake up the controller from the sleep if interrupt occurs, but the Interrupt Service Routine located in the interrupt vector will not be executed and the code of the program will continue execution. The interrupt flag will set when its associate event occurs regardless of whether or not the GIE bit is set.
After switch is released, the RBIF flag is cleared and the device again is put to the sleep mode at the beginning of the loop..