14M2 Interrupts

DougP

New Member
I am using switches on pins c.0,c.1, and c.2 to generate an interrupt. How can I determine which input has caused the interrupt? ( Just getting started with the Picaxe )

Also, is there a way to be notified by email when a reply has been received? Thanks for your help.
 

westaust55

Moderator
Welcome to the PICAXE forum.

The easy way is to use the SETINT command to monitor the three PortC pins.
Use the NOT parameter to look for a change in just one of the three.

Say you have pull down resistors so they are all low then you will check for the situation when they are NOT all low.
Within your Interrupt: subroutine you will need to individually rest each of the three pins to ascertain which have switched to the alternate/high state. Likewise good to check they are all back at the original/desired state before re-enabling the interrupts again.
 

Goeytex

Senior Member
Hi and Welcome,

With the 14M2 there is no flag byte that indicates which pin generated the interrupt. Unless you absolutely need to use an interrupt, it may be more practical to use "if then" statements or button commands in a loop.

However, If the switch press is long enough(it should be). you can read the state of the the pin as soon as the program jumps to the interrupt routine.

example:

Code:
#picaxe 14M2
#no_data
#terminal 19200

symbol switch1 = PinC.0
symbol switch2 = PinC.1
symbol switch3 = Pinc.2 
symbol iFlag = b0


INIT:
setfreq M16
setint OR %00000111,%00000111

MAIN:
do
    pause 1000 '// Waitng for switch press 
    
loop

interrupt:
pause 10    [COLOR="#008000"] '// ~ 5ms to  Debounce Switch  (May need to adjust) 
[/COLOR]
[COLOR="#008000"]'// switch should still be pressed[/COLOR]
if switch1     = 1 then : iFlag = 1
elseif switch2 = 1 then : iFlag = 2
elseif switch3 = 1 then : iFlag = 3
endif 


do  while pinc.0 = 1 or pinc.1 = 1 or pinc.2 = 1   [COLOR="#008000"] '// Wait for switch release[/COLOR]
loop

if iFlag = 1 then 
    sertxd ("Switch 1 Pressed",cr,lf)
else if iFlag = 2 then
    sertxd ("Switch 2 Pressed",cr,lf)
else if iFlag = 3 then
    sertxd ("Switch 3 Pressed",cr,lf)
endif

iFlag = 0   [COLOR="#008000"] ;// Clear the flag[/COLOR]
setint OR %00000111,%00000111
return
 
Last edited:
Top