Positron Compiler Documentation

Typical format of the interrupt handler with 18F devices.

Positron8 · Revision 4.0.6.5 · PDF page 468

As with both types of 14-bit core devices, the interrupt handler subroutine must also follow a fixed pattern.

• First, the Context Save command should be issued, as this will save any compiler system variables and SFRs used. The microcontroller itself will save the contents of the STATUS, BSR and WREG registers for a high priority interrupt.

• 18F devices have two interrupt vectors for high and low priority interrupts, see On_Low_Interrupt. However, both of these must follow the rules laid down for 14-bit core devices, in that the cause of the interrupt must be ascertained before the appropriate code is performed, and any interrupt flag that needs clearing must be cleared 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 1 mnemonic.

Note that the STATUS, BSR and WREG registers will automatically be restored by the microcontroller once the interrupt is exited from a high priority interrupt.

Upon exiting the interrupt, a simple Retfie 1 (Return From Interrupt Fast) mnemonic can be used, as long as the Context Save command is not issued and it is certain that the interrupt handling subroutine is not disturbing any compiler system variables or device SFRs.

Note. On all devices, the code within the interrupt handler should be as quick and efficient as possible because while it's processing the code, the main program is halted. When inside an interrupt, care should be taken to ensure that the watchdog timer does not time-out, if it's enabled. Placing a ClrWdt mnemonic at the beginning of the interrupt handler will usually prevent this from happening. An alternative approach would be to disable the watchdog timer altogether at programming time, which is the default of the compiler.

View original PDF page 468Open page in PDFOriginal PDF page 468