Keywords: sdccman

## 4.7.15 Interrupts

An interrupt service routine (ISR) is declared using the __interrupt keyword.

  void isr(void) __interrupt (n)

  {

  ...

  }

n is the interrupt number, which for PIC18F devices can be:

n | Interrupt Vector | Interrupt Vector Address
0 | RESET vector | 0x000000
1 | HIGH priority interrupts | 0x000008
2 | LOW priority interrupts | 0x000018

When generating assembly code for ISR the code generator places a GOTO instruction at the Interrupt Vector Address which points at the generated ISR. This single GOTO instruction is part of an automatically generated interrupt entry point function. The actual ISR code is placed as normally would in the code space. Upon interrupt request, the GOTO instruction is executed which jumps to the ISR code. When declaring interrupt functions as _naked this GOTO instruction is not generated. The whole interrupt functions is therefore placed at the Interrupt Vector Address of the specific interrupt. This is not a problem for the LOW priority interrupts, but it is a problem for the RESET and the HIGH priority interrupts because code may be written at the next interrupt's vector address and cause indeterminate program behaviour if that interrupt is raised.4.4

n may be omitted. This way a function is generated similar to an ISR, but it is not assigned to any interrupt.

When entering an interrupt, currently the PIC16 port automatically saves the following registers:

- WREG
- STATUS
- BSR
- PROD (PRODL and PRODH)
- FSR0 (FSR0L and FSR0H)

These registers are restored upon return from the interrupt routine.4.5