User manual
mikroPascal PRO for PIC32
MikroElektronika
141
Interrupt Example
Here is a simple example of handling the interrupts from Timer1 (if no other interrupts are allowed):
program Timer1_interrupt;
procedure Timer1Int(); iv IVT_TIMER_1; ilevel 7; ics ICS_SRS;
begin
T1IF_bit := 0; // Clear T1IF
LATB := not PORTB; // Invert PORTB
end;
begin
AD1PCFG := 0xFFFF; // Initialize AN pins as digital
TRISB := 0; // initialize PORTB as output
LATB := 0xAAAA; // Initialize PORTB value
TMR1 := 0; // reset timer value to zero
PR1 := 65000; // Load period register
T1IP0_bit := 1; // set interrupt
T1IP1_bit := 1; // priority
T1IP2_bit := 1; // to 7
TCKPS0_bit := 1; // Set Timer Input Clock
TCKPS1_bit := 1; // Prescale value to 1:256
EnableInterrupts();
T1IE_bit := 1; // Enable Timer1 Interrupt
ON__T1CON_bit := 1; // Enable Timer1
end.