I am trying to use the timer 1 of a PIC32MX250F128B MCU so that it would rise an interrupt flag after every 2 seconds. I'm using the Fast RC Osc with PLL which is working at 8 MHz, and Pb_Clk = Sys_Clk.
So I examined some examples here and some tutorials and created such code which compiles without any errors:
Code: Select all
void Timer1Interrupt() iv IVT_TIMER_1 ilevel 7 ics ICS_SOFT {
T1IF_bit = 0;
LATB.B2 = ~ PORTB.B2;
}
void main() {
JTAGEN_bit = 0;
ANSELA = 0;
ANSELB = 0;
TRISA = 0;
TRISB = 0;
LATA = 0;
LATB = 0;
SYSKEY = 0xAA996655; //unlock clock
SYSKEY = 0x556699AA;
T1CON = 0; //clear the control register
TMR1 = 0; //set timer 1 to zero
TCKPS0_bit = 1; // Set Timer Input Clock
TCKPS1_bit = 1; // Prescale value to 1:256
T1IP0_bit = 1; //set interrupt priority level to 7
T1IP1_bit = 1;
T1IP2_bit = 1;
T1IE_bit = 1; //enable the timer 1 interrupt
T1IF_bit = 0; //clear the interrupt flag of timer 1
PR1 = 62500; //MCU 8 MHz -> cycle = 125 ns; timer tick = 256 * 125 ns = 0.032 ms; 2 s/0.032 ms = 62500
ON__T1CON_bit = 1; // Enable timer 1
EnableInterrupts();
}
I added the project folder, too. Thanks for any help!