3.3.6.1 How Do I Use Interrupts In C?
Be aware of what sort of interrupt hardware is available on your target device. Most baseline PIC devices do not implement interrupts at all; baseline devices with interrupts and mid-range devices utilize a single interrupt vector. PIC18 devices implement two separate interrupt vector locations and use a simple priority scheme. Some PIC18 devices use a vectored interrupt controller to invoke multiple interrupt functions.
In C source code, a function can be written to act as the interrupt service routine (see 5.9.1 Writing an Interrupt Service Routine). Such functions save and/or restore program context before and/or after executing the function body code and a different return instruction is used (see 5.9.4 Context Switching).
Code inside the interrupt function can do anything you like, but see 3.5.7 How Can I Make My Interrupt Routine Faster? for suggestions to enhance real-time performance.
Prior to any interrupt occurring, your program must ensure that peripherals are correctly configured and that interrupts are enabled (see 5.9.5 Enabling Interrupts). On PIC18 devices, you must specify the priority of interrupt sources by writing the appropriate SFRs.