- When using interrupt priority
levels, set IPEN and then select the user-assigned priority level for the
interrupt source by writing the control bits in the appropriate IPRx control
register.
Important: At a device Reset, the IPRx registers are initialized such
that all user interrupt sources are assigned to high priority.
- Clear the Interrupt Flag Status
bit associated with the peripheral in the associated PIRx STATUS register.
- Enable the interrupt source by
setting the interrupt enable control bit associated with the source in the
appropriate PIEx register.
- If the vector table is used
(MVECEN =
1
), then set up the start address for the Interrupt
Vector Table using IVTBASE. See the Interrupt
Vector Table Contents section for more details.
- Once IVTBASE is written to, set
the interrupt enable bits in INTCON0.
- An example of setting up
interrupts and ISRs can be found below.
Setting Up Vectored Interrupts
Using XC8
void __interrupt(irq(IRQ_SW), base(0x3008)) SW_ISR(void)
{
PIR0bits.SWIF = 0;
LATCbits.LATC0 ^= 1;
}
void __interrupt(irq(default), base(0x3008)) DEFAULT_ISR(void)
{
}
void INTERRUPT_Initialize (void)
{
INTCON0bits.GIEH = 1;
INTCON0bits.GIEL = 1;
INTCON0bits.IPEN = 1;
PIE0bits.SWIE = 1;
PIE0bits.HLVDIE = 1;
IPR0bits.SWIP = 0;
IVTBASEU = 0x00;
IVTBASEH = 0x30;
IVTBASEL = 0x08;
}