Couldn't we use LOOKUP for this??
my_var = port A
Lookup my_var,[0,1,2,3,4,]pin_pressed
wouldn't pin_presed now hold the pin that was triggered?
Victor
Couldn't we use LOOKUP for this??
my_var = port A
Lookup my_var,[0,1,2,3,4,]pin_pressed
wouldn't pin_presed now hold the pin that was triggered?
Victor
From what is written in the manual:
"LOOKUP B0,[“Hello!”],B1 ' Get character number B0 from string to variable B1"
So if you lookup portA then you will have a value equal to the bit rank of the bits that are set. I only need to find the first bit set when reading the PORTA register from LSB to MSB.
With LOOKUP, if the bits 0 and 2 are set, portA will be = 5, that is not the pin_pressed.
(It will will return the value of the 5th constant).
The only way I found till now is to use redundant code like:
if porta.0 = 0 then
pin = 0
Goto bypass
endif
if porta.1 = 0 the
pin = 1
Goto bypass
endif
...etcetera
That's not nice but it works
This may not be any nicer, and I'm not even sure if it'll work...but...
Code:temp var byte pin var byte pin = 0 : temp = porta 'initial pin to zero and save porta to temp loop: pin = pin + 1 : if (temp.0[pin] <> 0) AND (pin <> 4) then loop got_pin: 'when you get here, if pin = 5 then porta.0 thru porta.3 <> 0
This seems to be the way to index the pin registers.
In fact before checking the replies on the forum (and your reply) I've tried the tutorial from BRUCE where he is using:
SYMBOL TRIGGERED_PIN = PORTA
Then
IF (TRIGGERED_PIN.0[index] == 0) THEN
...
and it worked fineI'm very happy.
You have substituted arrogance for intelligence
Time enough
nostromo signing off
Bookmarks