Information

© 2007 Microchip Technology Inc. DS80277C-page 7
PIC18F2410/2510/4410/4510
2. C Language Programming: 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 han-
dler 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,
then the interrupt is treated as high priority in
spite of the pragma interruptlow directive.
The code segment shown in Example 3
demonstrates the work around using the C18
compiler:
EXAMPLE 3:
An optimized C18 version is also provided in
Example 4. This example illustrates how it
reduces the instruction cycle count from
10 cycles to 3:
EXAMPLE 4:
#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 */
#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)
{
...
}