#include <xc.h> #include <sys/attribs.h> /* Config bits */ #pragma config FSRSSEL = PRIORITY_7 /* Assign the SRS to level 7 priority handlers */ void __ISR (_TIMER_2_VECTOR, IPL7SRS) T2Interrupt(void) { // Toggle LED LD1 LATGINV = _LATG_LATG6_MASK; // Reset interrupt flag IFS0bits.T2IF = 0; } int main(void) { // Initialization T2CONbits.TON = 0; /* turn off Timer 2 */ T2CONbits.TCKPS = 7; /* pre-scale = 1:256 (T2CLKIN = 39062.5 Hz) */ PR2 = 3906; /* T2 period ~ 100mS */ TMR2 = 0; /* clear Timer 2 counter */ IPC2bits.T2IP = 7; /* Set Timer 2 interrupt priority to 7 */ IFS0bits.T2IF = 0; /* Reset the Timer 2 interrupt flag */ IEC0bits.T2IE = 1; /* Enable interrupts from Timer 2 */ INTCONSET = _INTCON_MVEC_MASK; /* Set the interrupt controller for multi-vector mode */ __builtin_enable_interrupts(); /* Set the CP0 Status IE bit to turn on interrupts globally */ while(1); /* main application loop */ }