#include<p32xxxx.h>
#include<plib.h>
// timer2 initialization
void timer2_init(void)
{
T2CONbits.TON = 0; /* turn off Timer 2 */
T2CONbits.TCKPS = 7; /* pre-scale = 1:256
PR2 = 11000;
TMR2 = 0;
}
void __ISR(_TIMER_2_VECTOR, ipl7) T2InterruptHandler(void)
{
// toggle RA1 pin
LATAbits.LATA1 ^= 1;
// reset the overflow interrupt flag
IFS0bits.T2IF = 0;
}
main()
{
// init I/Os
DDPCONbits.JTAGEN = 0;
TRISA = 0xff00; // PORTA LSB as outputs which are connected to LEDs
PORTA = 0;
// initialize timer
timer2_init();
IPC2bits.T2IP = 7;
IFS0bits.T2IF = 0;
IEC0bits.T2IE = 1;
T2CONbits.TON = 1;
while(1);
}// main