Datasheet
PICkitâ„¢ 3 Debug Express
DS41370C-page 50 © 2009 Microchip Technology Inc.
When an interrupt occurs and the Master Interrupt signal is asserted, the PIC
microcontroller finishes executing the current instruction, stores the next address on
the Return Address Stack, and then jumps to an interrupt vector. At the interrupt vector
it begins executing a function designated as the Interrupt Service Routine. When this
function exits, program execution returns to the address stored on the Return Address
Stack.
Interrupts allow hardware events to be acted upon very quickly and regardless of the
state of the main program because they cause the immediate execution of dedicated
code.
The PIC18FXXXX architecture supports up to two levels of interrupt priority, each of
which have a logic structure like that in Figure 3-37. Most interrupts have a Priority bit
associated with the interrupt flag and enable that assigns it to one of the two priority
levels. Using priority levels is optional, and the PIC18FXXXX may be configured to use
only one level priority.
When two levels of interrupt priority are used, an interrupt of either priority level may
interrupt the main program. However, only a high priority interrupt may interrupt a low
priority interrupt, and nothing may interrupt a high priority interrupt. As shown in Figure
3-38, when a low priority interrupt event occurs during execution of statement3 in the
main code, the program jumps to begin executing the low priority interrupt function.
During execution of the lo_statement2, a high priority interrupt event occurs,
causing program execution to jump to the High Priority Interrupt function. When the
high priority function completes and exits, execution is returned to where it left off in the
low priority function. Similarly, when the low priority function completes and exits,
program execution returns to where it left off in the main code, at statement4.
FIGURE 3-40: PRIORITY INTERRUPT EXECUTION FLOW
The high priority interrupt vector is at program memory address 0x0008. The low
priority interrupt vector is at program memory address 0x0018. If interrupt priorities are
not used, all interrupts jump to the high priority vector at 0x0008.
3.8.2 Exploring the Lesson 8 Source Code
The first thing to note is that the Directions variable is now global, so it may be
accessed in the Interrupt Service Routine functions.
When using interrupts, the interrupt vectors must be defined and placed at the
appropriate vector addresses using the #pragma code directives. An inline assembly
GOTO statement redirects program execution to the interrupt functions, whose name
serves as the GOTO argument.