Information

PIC18F2455/2550/4455/4550
DS80478A-page 6 © 2009 Microchip Technology Inc.
C Programming Language
The exact work around depends on the compiler in
use. Please refer to your C compiler documentation
for details.
If using the Microchip MPLAB
®
C18 C Compiler,
define both high and low-priority interrupt handler
functions as “low priority” by using the
pragma interruptlow directive. This
directive instructs the compiler to not use the
RETFIE FAST instruction. If the proper high-
priority interrupt bit is set in the IPRx register, the
interrupt is treated as high priority in spite of the
pragma interruptlow directive.
The code segment shown in Example 2
demonstrates the work around using the C18
compiler.
EXAMPLE 2: INTERRUPT WORK AROUND – C
An optimized, C18 version of the code is pro-
vided in Example 3. This example illustrates how
to reduce the instruction cycle count from
10 cycles to 3.
Affected Silicon Revisions
EXAMPLE 3: INTERRUPT WORK
AROUND – OPTIMIZED C18
#pragma interruptlow MyLowISR
void MyLowISR(void)
{
// Handle low priority interrupts.
}
// Although MyHighISR is a high priority interrupt, use interruptlow pragma so that
// the compiler will not use retfie FAST.
#pragma interruptlow MyHighISR
void MyHighISR(void)
{
// Handle high priority interrupts.
}
#pragma code highVector=0x08
void HighVector (void)
{
_asm goto MyHighISR _endasm
}
#pragma code /* return to default code section */
#pragma code lowVector=0x18
void LowVector (void)
{
_asm goto MyLowISR _endasm
}
#pragma code /* return to default code section */
A3 B4 B5 B6 B7
X
#pragma code high_vector_section=0x8
void high_vector (void)
{
_asm
CALL high_vector_branch, 1
_endasm
}
void high_vector_branch (void)
{
_asm
POP
GOTO high_isr
_endasm
}
#pragma interrupt high_isr
void high_isr (void)
{
...
}