#include <xc.h>
#include <sys/attribs.h>

void __ISR_AT_VECTOR (_TIMER_2_VECTOR, IPL4SRS) 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 = 31250 Hz) */
    PR2 = 3125;                    /* T2 period = 100mS */
    TMR2 = 0;                        /* clear Timer 2 counter */

    IPC2bits.T2IP = 4;                /* Set Timer 2 interrupt priority to 4 */
    IFS0bits.T2IF = 0;                /* Reset the Timer 2 interrupt flag */
    IEC0bits.T2IE = 1;                /* Enable interrupts from Timer 2 */

    PRISS = 0x76543210;                /* assign shadow set #7-#1 to priority level #7-#1 ISRs */

    INTCONSET = _INTCON_MVEC_MASK;    /* Configure Interrupt Controller for multi-vector mode */

    __builtin_enable_interrupts();    /* Set the CP0 Status register IE bit high to globally enable interrupts */

    T2CONbits.TON = 1;                /* Enable Timer 2 peripheral */

    while(1);                        /* main application loop */

}