Enabling Interrupts

Two macros are available, once you have included <xc.h>, that control the masking of all available interrupts. These macros are ei(), which enable or unmask all interrupts, and di(), which disable or mask all interrupts.

On all devices, they affect the GIE bit in the INTCON or INTCON0 register. These macros should be used once the appropriate interrupt enable bits for the interrupts that are required in a program have been enabled.

For example:

ADIE = 1;  // A/D interrupts will be used
PEIE = 1;  // all peripheral interrupts are enabled
ei();      // enable all interrupts
// ...
di();      // disable all interrupts
Note: Never re-enable interrupts inside the interrupt function itself. Interrupts are automatically re-enabled by hardware on execution of the retfie instruction. Re-enabling interrupts inside an interrupt function can result in code failure.