Shop OBEX P1 Docs P2 Docs Learn Events
Reading keypad with "serin" — Parallax Forums

Reading keypad with "serin"

bsparkybsparky Posts: 52
edited 2005-10-24 02:35 in BASIC Stamp
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.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-01 00:15
    Hello,
    ·· 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.


    KeyScan:
      if IN14 = 1 THEN KeyScan
      SERIN 15, 84, [noparse][[/noparse]x]
      x = x - 48
      if x < 10 then KeyScan2
      x = x - 7
    KeyScan2:
      LOOKUP x,[noparse][[/noparse]49,50,51,65,52,53,54,66,55,56,57,67,42,48,35,68],y
      RETURN
    

    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
  • bsparkybsparky Posts: 52
    edited 2005-09-01 13:09
    Thanks Chris, that clears it up. Just one other thing about your code IF IN14 = 1 THEN KEYSCAN should that read = 0 the EDE1144 chip pulses high when a key is pressed making IN14 high or 1 right. One other thing on the BS2 I'm using 396 for 2400 baud mostly because I read in the help file that the BS2 can have trouble with 9600 baud which the EDE1144 will support also. You show 84 what BS and baud rate is this for or was that just an example? Thanks
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-01 14:13
    bsparky,

    ·· 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
  • bsparkybsparky Posts: 52
    edited 2005-09-01 18:14
    Yes Chris Thanks. I would appriciate looking at you other code. My code always seems so bulky compared to others.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-01 18:29
    Okay,

    ·· 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.
    LOOKUP x,[noparse][[/noparse]1,2,3,10,4,5,6,11,7,8,9,12,13,0,14,15],y
    

    ·· 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
  • bsparkybsparky Posts: 52
    edited 2005-09-01 20:44
    Yes I wish it were cheaper, I paid 7.50 but the real killer was the two 7219 at 10.75 a piece then with the Stamp this whole scoring system is costing a bit. But at least the EDE1144 is saving me I/O.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-02 03:15
    By the way, a colleague just reminded me of something I should've known better about.· In those routines I copied that from really old code, but you shouldn't use single letter variables like x and y.· Instead x should've been something descriptive, like inKey, and y should've been something like outKey.· =)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • KenMKenM Posts: 657
    edited 2005-09-02 04:49
    Let me guess.....JW?
    Chris Savage (Parallax) said...
    By the way, a colleague just reminded me of something I should've known better about.
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ken
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-02 14:34
    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
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-09-02 14:46
    I try to follow descriptive variable naming with one exception, generic iteration variables that are repeatedly used in different circumstances and they are always I,J,K,... for however many nested levels there are.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • bsparkybsparky Posts: 52
    edited 2005-09-02 19:13
    Thanks Chris quess I'm like you in the old days I was always using x and y variables for counting. I believe in basic on the 8 bit computers they used less memory and you could just reuse them the program and didn't have to define more. Will keep going with it still having some trouble getting the key to come out right, when I debug for y I not get anything nothing. Will work on it more this weekend and see if I can find my fault. Thanks for the Help.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-02 19:35
    bsparky,

    ·· 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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-02 23:13
    Okay,

    ·· 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
  • NewzedNewzed Posts: 2,503
    edited 2005-09-02 23:28
    I made a little keypad encoder.· It is a non-matrix keypad and has a 16F628 on the inside of the keypad box..· The 16F628 detects when a button is pressed and serouts the appropriate number to my Stamp.· Takes one Stamp line for the serin.· Very effective and very cost efficient.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
  • SMurphySMurphy Posts: 6
    edited 2005-10-22 23:42
    Hi everyone,

    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.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2005-10-23 02:08
    SMurphy,

    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-10-23 02:34
    Well, first of all, you're using a BS2p, so the SERIN command's Baud Rate value would have to be changed from 84 to 240.· Did you make that change?· PJ is also correct in that you should still have a resistor on the C3 input even if you're not using it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-10-23 02:41
    Hello again...Alright, one more thing clicks in mind as well...All of the lines in the schematic in the datasheet that are tied to V+ need to be tied to V+ or this won't work.· This includes the Baud select pin, otherwise the baud rate values are off (again).

    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
  • knightofoldcodeknightofoldcode Posts: 233
    edited 2005-10-23 08:26
    Also, just in case none of those seemed to fix it the EDE1144 must have a crystal used. I know the spec sheet made me think it didn't need one, then when mine wasn't working I kept going, okay.... it says that a crystal is optional........ But it's essentially not optional, and is required.


    Knight.
  • SMurphySMurphy Posts: 6
    edited 2005-10-23 09:31
    Thanks guys for your help.

    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. jumpin.gif
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-10-23 17:25
    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
  • knightofoldcodeknightofoldcode Posts: 233
    edited 2005-10-24 02:35
    Chris Savage (Parallax) said...
    Sean,
    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).

    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.
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-
Sign In or Register to comment.