Interrupt concept

russbow

Senior Member
I want to select either of two display routines to feed a common display.
I thought that using a button to toggle a "flag", and using that "flag" value
to select which routine to use would be the route to go.

However, I dont want to have to hold the button down whilst the whole program loops
so perhaps an interrupt is the way to go.

Does this pseudo code lead me in the right direction?

Code:
setint %00000010,%0000001

do 

lots of things

if flag =1 gosub display 1

else gosub display 2

loop

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

interrupt:

toggle flag

do

loop until pin 1=0

setint %00000010,%0000001

return

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
I have never dealt with interrupts before so any pifalls in my thinking here.
Toggle flag is a concept, not a command.

Thanks, Russ
 

bluejets

Senior Member
I think how it works is, you make the program watch the switch, which will interrupt if operated, and this in turn sets the flag.
Some programming requires the flag to be reset afterwards but not sure about picaxe.
 

russbow

Senior Member
I have tried this code. It's not quite there.
It does not display until the button is pressed, - then shows "Disp 1 "
Further presses do not change anything. Pin c.3 tied low by 10K

Code:
#picaxe08m2


symbol LCD=c.1

b1=1:b2=0

serout LCD,N2400,(254,1)

pause 500

setint %00000001,%0001000	'Note active value of 1 on pin c.3

do 

sertxd ("b1= ",#b1," b2= ",#b2,cr,lf)

if b1 =1 then gosub display1


if b1 =0 then gosub display1

pause 2000

loop

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

display1:

serout LCD,N2400,(254,128,"Disp 1")

return
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

display2:

serout LCD,N2400,(254,128,"Disp 2")

return
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
interrupt:

swap b0,b1

do until pinc.3 = 0

loop 

setint %00000001,%0001000

return

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Are my setint values right ?
 
Last edited:

rossko57

Senior Member
You seem to initialise b1 & b2, but work with b0 & b1

There is nothing in the code to call 'display2', perhaps you meant one of the gosubs to refer to that?
 

russbow

Senior Member
Thank you both very much. Sorted!!
@Rossko57 - second gosub was a cut n paste error. Didn't spot the variable mix up either.
@Tech - no excuse for 7 bits, but theory was wrong anyway. Understand now.

Exactly what I wanted.
 

russbow

Senior Member
....... and on the 18m2 chip ?

From manual 2
SETINT input,mask,port

- input is a variable/constant (0-255) which specifies input condition.
- mask is variable/constant (0-255) which specifies the mask
- port is the X2 port (A,B,C,D)
Does this hold good for the 18m2 chip? Otherwise how do I define pin b.1 as opposed to pin c.1
 

hippy

Technical Support
Staff member
how do I define pin b.1 as opposed to pin c.1
From the same page ...

Information:
The setint command causes a polled interrupt on a certain input pin condition. This can be a combination of pins on the default input port (portC). X2 parts can also be redirected to look at a different port if required.
 
Top