next up previous contents index
Next: 4.6.15 Generic Pointers Up: 4.6 The PIC16 port Previous: 4.6.13 Function return values   Contents   Index

4.6.14 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 genetated ISR. This single GOTO instruction is part of an automatically generated interrupt entry point function. The actuall 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 undeterminate program behaviour if that interrupt is raised.4.2

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:

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


next up previous contents index
Next: 4.6.15 Generic Pointers Up: 4.6 The PIC16 port Previous: 4.6.13 Function return values   Contents   Index
2008-12-05