Shop OBEX P1 Docs P2 Docs Learn Events
Nib, bytes & lookups — Parallax Forums

Nib, bytes & lookups

KAD3KAD3 Posts: 3
edited 2004-11-13 01:09 in BASIC Stamp
I am not a very good programer as you will see from the following code.

This code sort of works.· I am trying to output a 1 or 0 at various pins of BSP40, based on a key press from a simple 4x4 matrix keypad.· I am using a EDE1144 keypad encoder which uses a single pin on the stamp.· Seems to work OK.

The Lookup table out puts the correct·pin sequence that whant to out put. (except for A,B,C,D etc)
My problem is that I do not understand what reuslt I shuold expect from pressing keys other than 0 to 9.· Such as A,B,C,D,CR,BS.

Pressing keys like Back Space does not return a value that I would expect.· Like 41,42,43 etc.

I am confussed over $ values and DEC values.· Should I get a $46 value when I press key 15, or just a decimal equiv?

Have I got·the Nib and Byte·correct?
·
Any ideas would be appreciated.

{$STAMP BS2p}
'{$PBASIC 2.5}
'{$PORT COM1}
DIRS=%0000000011111001······· '0=input >> 1=output
bps CON 240·················· '9600 Baudrate
dly CON 30··················· 'Global pause delay..
key· VAR· Nib················ 'key input varible
result· VAR· Nib············· 'decoded key
status· VAR· OUTS.LOWBIT
MAINIO
Rx· CON 2····················· 'Serin (receive) pin 2
GOTO reset····················· 'reset display
keyloop:
SERIN Rx,bps,[noparse][[/noparse]key]
IF key=13 THEN TGL··········· 'if key 13 is pressed then toggle result
DEBUG "actual key=··· " ,DEC key,CR
Keyscan:
LOOKUP key,[noparse][[/noparse]30,10,9,15,13,12,11,8,15,14,44,41,42,40,39,38],result··· 'puts keypad number in correct seq for pin output
DEBUG "result is··· ", DEC result, CR
ad1:
LOW 4······························ 'address1
HIGH 5
LOW 6

IF result=<15 THEN OUTPUT(result)··· 'output to this pin

tx:
HIGH 7······························· 'pulse pin 7 to tx
PAUSE 200
LOW 7
PAUSE 200
GOTO rr
tgl:
DEBUG "toggle"
TOGGLE(result)
GOTO tx
RR:······································ 'Read Relay
IF status(result)=1 THEN displayc
GOTO displayo

displayc:································· 'display relay closed
SEROUT 0,bps,[noparse][[/noparse]254,192]
PAUSE dly
SEROUT 0,bps,[noparse][[/noparse]"RLY ", DEC(result), " CLOSED "]· 'display status of selected relay
PAUSE 100
GOTO Keyloop
displayo:
SEROUT 0,bps,[noparse][[/noparse]254,192]
PAUSE dly
SEROUT 0,bps,[noparse][[/noparse]"RLY ", DEC(result), " OPEN· "]
PAUSE 100
GOTO Keyloop
reset:
DEBUG "reset",CR
SEROUT 0,bps,[noparse][[/noparse]1]
PAUSE dly
SEROUT 0,bps,[noparse][[/noparse]12]
PAUSE dly
SEROUT 0,bps, [noparse][[/noparse]"READY"]
GOTO Keyloopd be appreciated.
Sign In or Register to comment.