Typical format of the interrupt handler with enhanced 14-bit core devices.
As with standard 14-bit core interrupts, the interrupt handler subroutine must follow a fixed pattern.
- First, the Context Save command should be issued, as this will save any compiler sys-
tem variables and SFRs used. The microcontroller itself will save the contents of the STATUS, PCLATH, BSR, FSR0L\H, FSR1L\H and WREG registers.
- As with standard 14-bit core devices, enhanced 14-bit core devices have a single inter-
rupt vector, therefore the same rules apply as outlined above concerning the establishment of the cause of the interrupt. Not forgetting to clear any interrupt flag that needs clearing before exiting the interrupt.
- The Context Restore command should be issued at the end of the interrupt handler, as
long as its corresponding Context Save command was used previously. This will restore any compiler system variables and SFRs, then exit the interrupt using the Retfie mnemonic.
Note that the STATUS, PCLATH, BSR, FSR0L\H, FSR1L\H and WREG registers will automatically be restored by the microcontroller once the interrupt is exited.
As with standard 14-bit core devices, any compiler variable or device SFR that is used by a command will be saved and restored as long as they reside within the Context Save and Context Restore commands. This is termed Managed Interrupts.
Note that the Context Save and Context Restore commands are not required unless managed interrupts are implemented, in which case use the Retfie mnemonic to exit the interrupt handler. However, you must be certain that the interrupt handler is not disturbing any compiler system variables or SFRs, or your program will not run correctly.