User manual
142
mikoBasic PRO for PIC32
MikroElektronika
Interrupt Example
Here is a simple example of handling the interrupts from Timer1 (if no other interrupts are allowed):
program Timer1_interrupt
sub procedure Timer1Int() iv IVT_TIMER_1 ilevel 7 ics ICS_SRS
T1IF_bit = 0 ‘ Clear T1IF
LATB = not PORTB ‘ Invert PORTB
end sub
main:
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 ‘ Enable all interrupts
T1IE_bit = 1 ‘ Enable Timer1 Interrupt
ON__T1CON_bit = 1 ‘ Enable Timer1
end.