multiple interrupts?

robbyraven

New Member
Hi everyone,

I'm using the interrupt command with my 18X so that whenever pin 2 is taken high, b0=b0+1, and the new value for b0 is displayed via output 0 to a serial LCD. This is working fine, the relevant code is below:

init:
b0=0
pause 500
serout 0,N2400,(254,128) ‘ move to start of first line
serout 0,N2400,("temp diff=",#b0,"c")‘ output text
pause 1000
setint %00000100,%00000100 'interrupt when pin 2 goes high

main: etc etc....

interrupt:
b0=b0+1
pause 250
if pin2=1 then interrupt
serout 0,N2400,(254,128) ‘ move to start of first line
serout 0,N2400,("temp diff=",#b0,"c")‘ output text
setint %00000100,%00000100
pause 1000
return

So b0 starts as zero, and every time I press the button to take pin2 high, b0 increases by one and displays briefly on the LCD. However, I need to be able to do the same thing in reverse i.e. every time I press yet another button, taking another pin high, I need b0 to decrease by one. However I can't figure out how to have two different interrupt commands operative at the same time. Picaxe manual doesn't seem to shed any light on this. Can anyone tell me how to run two interrupts, or another clever way around this?

Also, I'm running out of inputs on my 18X project board. Pins 0 and 1 are analogue, 2 is taken up with my 'plus 1' switch, 3 and 4 are for serial, 5 doesn't exist and 6 and 7 are taken up with the two temperature sensors required for this project. Do I have to solder the 10k resistor across either R7 or R8? I'd rather not as the project board probably won't be the final resting place of this project.

Thanks again,

Rob
 

BeanieBots

Moderator
Obviously, you will need another input pin for your other button.
Wire up a switch to the 'new' input just as you have for the first button.
Now add a diode so that when it is pressed it also activates your interrupt input.
Now, if either button is pushed, the interrupt is triggered.
The first thing to do in the interrupt routine is to check the state of the inputs. If only the original input is active, then the original button button was pushed. If the 'new' input AND the original are active, then the 'new' button was pushed.
It's then just a case of jumping to the piece of code to do whatever you want done for each condition.
 

Technical

Technical Support
Staff member
To use either input0 or input1 as a digital input you will need to add the 10k resistor in positions R7 or R8. As BB says the diode then goes between the switch/resistor joint on each input.
 

hippy

Ex-Staff (retired)
Multiple interrupt sources can be used by diode-mixing two or more inputs to a single interrupt pin then when the interrupt occurs the code checks which source caused the interrupt. You need as many input pins as there are interrupt sources to determine which caused the interrupt.
 

BeanieBots

Moderator
I've not tried this, but I'm sure it would be possible to do something crafty with an analogue input. It is certainly possible to use an analogue input to detect MANY input buttons with a resistor network. (check projects section for example). So, as long as the button also activates the interrupt pin, then it would be a case of check the analogue voltage to see which button(s) caused it.
 
Top