Positron Compiler Documentation

Typical format of the interrupt handler with standard 14-bit core devices.

Source: Positron8 Compiler User Manual, PDF page 467

The interrupt handler subroutine must always follow a fixed pattern.

saved, this is termed context saving, and is performed when the command Context Save is issued. Variable space is automatically allocated for these registers in the shared portion of memory located at the top of RAM Bank 0. The Context Save command also instructs the compiler to save any compiler system variables and device SFRs (Special Function Registers) used within the interrupt handler. Note that "within the interrupt handler" means code between Context Save and Context Restore. It will not track any GoTo or GoSub commands.

terrupt must be ascertained by checking the appropriate flag. For example INTCON.T0IF for a Timer0 overflow interrupt, and only perform the relevant code for the relevant interrupt. This is accomplished by a simple If-EndIf. For example:

ISR_Handler:
  Context Save
                                  ' Save any variables or SFRs used
  If INTCONbits_T0IF = 1 Then
                                  ' Is it Timer0 that caused the interrupt?
     Print "Hello World"
                                  ' Yes. So do this code
     INTCONbits_T0IF = 0
                                  ' Clear the Timer0 overflow flag
  EndIf
  Context Restore
                                  ' Restore any variables or SFRs used and exit

If more than one interrupt is enabled, multiple If-EndIf conditions will be required within the single interrupt handling subroutine.

turned to their original conditions (context restoring) once the interrupt handler has performed its task. The Context Restore command is used for this. It also returns the program back to the main body code where the interrupt was called from. In other words it performs an assembler Retfie instruction.

The above code snippet will cause several compiler system variables and device SFRs to be saved and restored, thus causing little, or no, disturbance to the main body code.