This shows how to use INT1 and INT2 on a Picaxe20X2.It has be simulated on 28X2 and 40X2 parts and seemed to work fine.Watch out for the pullup command as it will cause problems with the simulator
Code:
; *******************************
; ***** Sample Header File *****
; *******************************
; Filename: Interrupt.bas
; Date: 28/01/10
; File Version:v1.0
; Written by: Jimmy Allen
; Function: Demonstrate how to use INT0,INT1 on PicaxeX2 parts
; Target PICAXE:PicaxeX2 parts
' Compiler: Program Editor 5.2.9
; *******************************
note:{
#rem
This code has been tested on a Picaxe20X2,Simulated on a Picaxe20X2 Picaxe28X2 and Picaxe40X2 and all seem to function properly
Line 26-28(pullup) needs to be commented out during simulation as it causes the Program Editor to stop responding.
w0 will overflow from 0xff to 0 or 0 to 0xff
there is no code to remove bouncing of switch contacts so w0 many inc or dec more than 1 for each button press
#endrem
}
init:{
#picaxe20x2
#terminal 9600
#no_data
#no_table
let w0 = 1000
'pullup %00011000 'Picaxe20X2 (refer to note)
'pullup on 'Picaxe28/40X2 (refer to note)
'pullup %00000110 'Picaxe28/40X2-3V (refer to note)
hintsetup %0000110 'set INT1 and INT2 to trigger Interrupt at falling edge
;Bit 7 - reserved
;Bit 6 - Interrupt 2 Trigger (1 = rising edge, 0 = falling edge)
;Bit 5 - Interrupt 1 Trigger (1 = rising edge, 0 = falling edge)
;Bit 4 - Interrupt 0 Trigger (1 = rising edge, 0 = falling edge)
;Bit 3 - reserved
;Bit 2 - Interrupt 2 Enable
;Bit 1 - Interrupt 1 Enable
;Bit 0 - Interrupt 0 Enable (not 20X2)
setintflags %00001000,%00001000 'enable interrupt flags
;flag0 hint0flag X2 parts - interrupt on INT0 hintsetup
;flag1 hint1flag X2 parts - interrupt on INT1 hintsetup
;flag2 hint2flag X2 parts - interrupt on INT2 hintsetup
;flag3 hintflag X2 parts - interrupt on any pin 0,1,2 hintsetup
;flag4 compflag X2 parts - comparator flag compsetup
;flag5 hserflag hserial background receive has occurred hsersetup
;flag6 hi2cflag hi2c write has occurred (slave mode) hi2csetuphint interrupts '
;flag7 toflag timer overflow flag settimer
setint %00000000,%00111110,C
}
main:{
sleep 0 'goto low power mode disabling all hardware except
goto main 'start infinite loop
end
}
Interrupt:{
let b0 = pinsC
hintflag = 0 'rest hintflags to 0
If hint1flag = 1 Then 'check to see if INT1 has bee triggered
inc w0 'increment w0 by 1
hint1flag = 0 'reset hint1flag to 0
End If
If hint2flag = 1 Then 'check to see if INT2 has bee triggered
dec w0 'decrement w0 by 1
hint2flag = 0 'reset hint2flag to 0
End If
sertxd (#w0,13,10) 'send value of w0 to serial terminal at N9600
SetIntFlags %00001000, %00001000 'renable hint interrupts
Return
}
Last edited: