Reading keypad with "serin"
bsparky
Posts: 52
I am using a keypad decoder IC from elaginc.com called EDE1144. If I read the spec sheet right it send the encoded button with a HEX value, if this is true how do I deal with this number by decimal? The keypad inputs $30 = 1 , $31 = 2 , $32 = 3 , $33 = uparrow
$34 = 4 , $35 = 5 , $36 = 6 , $37 = dnarrow
$38 = 7 , $39 = 8 , $41 = 9 , $42 = 2nd
$43 = clr , $44 = 0 , $45 = help , $46 = enter
Here is my code:
get_key:
do : loop while (key = 0)
serin 1,396, [noparse][[/noparse]tscore]
if tscore >$29 and tscore<$33 then add
if tscore >$33 and tscore<$37 then add
if tscore >$37 and tscore<$42 then add
if tscore = $44 then add
if tscore = $46 then return 'to the main program loop
add:
score=score + tscore
tscore = 0
goto get_key
end
I want score to have decimal value but will also need for it to multiply the digets by there placement such as the keys1,2,3 being one hundred and twenty three when I type enter or the hex value $46 signifing the end of the number entry. I have not thought about this part of the code because I could not get the decimal value I wanted.
Thanks for any help you can give.
$34 = 4 , $35 = 5 , $36 = 6 , $37 = dnarrow
$38 = 7 , $39 = 8 , $41 = 9 , $42 = 2nd
$43 = clr , $44 = 0 , $45 = help , $46 = enter
Here is my code:
get_key:
do : loop while (key = 0)
serin 1,396, [noparse][[/noparse]tscore]
if tscore >$29 and tscore<$33 then add
if tscore >$33 and tscore<$37 then add
if tscore >$37 and tscore<$42 then add
if tscore = $44 then add
if tscore = $46 then return 'to the main program loop
add:
score=score + tscore
tscore = 0
goto get_key
end
I want score to have decimal value but will also need for it to multiply the digets by there placement such as the keys1,2,3 being one hundred and twenty three when I type enter or the hex value $46 signifing the end of the number entry. I have not thought about this part of the code because I could not get the decimal value I wanted.
Thanks for any help you can give.
Comments
·· It happens that before I came to Parallax I had used the EDE1144 in several designs.· The main keypad code I used is listed below.· The EDE1144 was connected to P14 (data ready) and P15 (Serial Data).· When P14 went HIGH the routine would SERIN the key value from the IC and subtract 48 from it, allowing a decimal range of 0-15.
·· The values in HEX you are getting are merely how you're dealing with the numbers.· The values are ASCII numerals, not binary values, per se.· Anyway, the code then uses a LOOKUP to convert the key value into a value I want for it.
·· The second· calculation is for the keys with values above 10 so that the LOOKUP command works properly.· With this code you can assign any value you want based on what the EDE1144 returns.· Just replace the values in LOOKUP with values you want return for each index/offset.·· The value is returned in y.
EDIT:·The table currently corresponds to a keypad that looks like this...
123A
456B
789C
*0#D
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Post Edited (Chris Savage (Parallax)) : 9/1/2005 12:17:24 AM GMT
·· The Data Valid pin, in my case P14, is active low.· So I want the routine to sit in the loop until it does go low.· As for the baud rate, 84 is 9600 baud on a BASIC Stamp 2.· That routine was one of two I used.· The other one is slightly different.· It doesn't wait in a loop for the keypress, but rather continues it's loop until there's a keypress.· PBASIC 2.5 makes that routine more intuitive, so I will re-write it and post it later.· I hope that helps.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
·· I will dig that out tonight.· The code listed above is from a routine that stops and waits for a keypress to continue.· It is a subroutine that returns with the keypress.· The other version is called by a subroutine only when a keypress is detected, but also times out the SERIN command in case the data is lost somehow.· This prevents the routine from hanging at the SERIN command.
·· I think I forgot to mention that the code I posted returns the value listed in the LOOKUP list.· So you could return a 1, 2, 3, etc.· See the line below.
·· So you can basically get what you want.· One nice feature of the EDE1144 is unlike some of the other keypad decoder chips, this one has low EMI, since it scans the whole keypad only when there's a change.· Seems like I used to use a really noisy one, I think 74C922 which continuously scanned the keys, generating all kinds of EMI and P/S noise.· The price could stand to be a tad lower though.
·· Back in my Z80 days that's how I initiated a keyscan.· I would check the port for any change, then run the Row/Column scan.· The lines never toggled unless a key was pressed, which is really how it should be done.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Ken
·· Actually yes, and he's right.· There's nothing less descriptive than a single letter variable or label name, and I know better than that.· We try to keep each other on our toes, you know what I mean?·
bsparky,
·· Didn't find the other block of code last night.· I watched movies instead!· So I will dig it out this weekend (Maybe tonight).· In any event, keep plugging away with the chip.· When you don't have an LCD with KeyPad decoder, it's a life/pin-saver.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
·· I will put my test rig back together today around 3:00PM (PT) and get back on here and post updated code with a schematic today.· I think it's worth pulling out the EDE1144 and getting some updated code into my library for this chip.· What I'm thinking is that maybe your setup is slightly different (Row/Column connections).
·· Interestingly enough, I was also thinking of converting my Z80 ASM code over to PBASIC and using a 74HC595 and a 74HC165 to read an 8X8 matrix.· The only problem is I no longer have a 64-key keyboard to test on.· What we used to use in several designs was a Commodore surplus keyboard.· Radio Shack sold these for some time.· They weren't really a VIC-20 or C=64 keyboard, but some hybrid from like the C=16 or something.· Anyway they used an 8X8 matrix, and I had some nice code for that which also used a lookup table.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
·· Attached is the new complete demo code for the EDE1144 using our 2X16 Serial LCD Display for output.· The program basically reads the keys from my 4X4 KeyPad and outputs the ASCII value to the LCD.· I had it print a space after each character, so pressing each key displays all the characters on the display perfectly.· I pressed them from left to right, top to bottom.· The results can be seen in the attached picture.· I even connected the BEEP output, just to see what it was like, since I had never used it before.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Post Edited (Chris Savage (Parallax)) : 9/2/2005 11:59:24 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
I've tried using the program written by Chris with my EDE1144 on a BS2p
I've gone over the wiring several times moved it to a different part of the breadboard, changed wires, checked resistors,etc but i'm still having problems. I've also tried another EDE1144 that i have.
The keypress detect works fine but the data i'm receiving from the SERIN command doesn't make sense.
I'm using a 3x4 keypad so i would be expecting output like
123
456
789
*0#
But instead I'm getting the following, I've had to output it in DEC so that I could get a value otherwise it was sending escape characters to my screen.
(In DEC)
0··· 14·· 48
192 206 240
0·· 14·· 14
62 192 206
If anyone has any ideas I would be very grateful.
Regards,
Sean.
Is it possible that because it's a 3X4 you're using, instead of a 4X4, that·the EDE·figures it's getting those missing keys at the same time and bothching the output/s?· Do you have that unused Column Pin (C3) pulled-down (4K7 resistor) like the others?· I suppose it probably wouldn't like it if you weren't.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Now, I quickly translated my EDE1144 code to updated BS2 and BS2p versions that are completely commented.· Not only did I test this code on a BS2p just now, but I then tested it on a 3 X 4 keypad, and the same code works as long as the C3 (4th column) is still pulled down with the 4.7K.
Make sure you download the .bsp version and try it again.· It does work.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Knight.
The problem was with the baud rate, I was using 84 instead of 240.
I had already put the resistor in the C3 position (not initally I might add but during the first couple of hours before I posted the question)
Sorry for not getting back to you guys sooner but I live in Dublin, Ireland, so I was in bed fast asleep.
This forum and it's members are great.
Regards,
Sean.
·· Glad that fixed your problem.· Keep that in mind for future troubleshooting!· · Baud rate parameters vary amongst the different BASIC Stamp Models.
Knight,
·· I think the crystal is only optional to using a TTL Oscillator.· I think the options are 4 Mhz Parallel Cut Crystal or 4 Mhz TTL into the OSC1 pin and the other floats.· But I would have to re-check.· I have a stack of crystals so I just use those.· 7 years ago it was a pile of 4 Mhz TTL Oscillators (How things change).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Yeah, I noticed that, after a) it didn't work, and b) I reread the datasheet about 4 times. It was very misleading in the way it was wrote. [noparse]:([/noparse]
Knight.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-
This message transmitted with 100% recycled electrons.
-=-=-=-=-=-
Gravity doesn't exist. The Earth sucks.
-=-=-=-=-=-
Make a man a fire, and he will be warm for the night.
Light the man on fire, and he will be warm for the rest of his life.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-