Shop OBEX P1 Docs P2 Docs Learn Events
Serial input and processing question — Parallax Forums

Serial input and processing question

NickNick Posts: 11
edited 2005-05-01 03:47 in BASIC Stamp
Im trying to write some code with a 4X5 kaypad interface to a 4X20 LCD with keypad controller. I got the Keypad controller to send serial data to the stamp.

What·I need help with is how to setup the code to process the keypress. The controller exports the kaypad as ascii· A thru T.· I was going to use the SERIN command to store the keypress value in a variable.

From there·I was going to use IF THEN statments to execute the commands.· Is there a better way to do this?·

IF variable = "A" then execute_a
IF variable = "B" then execute_b
IF variable = "C" then execute_c
and so on....


I am also having trouble with the IF THEN ELSE command.· i copied the example from the stamp manual and it didnt recognize the command.· any ideas? anyone have any pointers on IF THEN ELSE??



Thanks again,
Nick

Comments

  • OrionOrion Posts: 236
    edited 2005-04-28 23:38
    What about

    Branch (variable-65), [noparse][[/noparse]execute_a,execute_b,execute_c]

    Seems to work if you use caps.

    Try

    ' {$PBASIC 2.5}

    at the top of your code for IF THEN ELSE.

    Post Edited (Orion) : 4/28/2005 11:45:02 PM GMT
  • NickNick Posts: 11
    edited 2005-04-29 01:38
    Ok, ill try that. Whats the reason for the -65 what does that do? Just curious.

    Thanks for the help.

    Nick
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-04-29 02:02
    Nick,

    ···It subtracts the ASCII value of the character from the value so that the lookdown command see a number from 0 through the highest entry, instead of a 65 through the highest entry.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-29 12:50
    65 is the ASCII value for "A", so...

    "A" - "A" = 0
    "B" - "A" = 1

    etc.· Does that make sense?· Remember, everything inside the Stamp is a number; it's how we use that number that is meaningful.
    Nick said...
    Ok, ill try that. Whats the reason for the -65 what does that do? Just curious.

    Thanks for the help.

    Nick
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • NickNick Posts: 11
    edited 2005-04-30 23:20
    ok guys,· i tried to store the keypad serial input to a variable. its not working

    kaypad VAR Byte

    SERIN 7, 396, [noparse][[/noparse]keypad]



    if i try to debug keypad it says keypad = 0· then it will say keypad = 255 about 10 -15 entries later.

    Isnt the SERIN command suposed to wait for data before it goes to the next command?

    How can i store it in the variable.



    Thanks again
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-01 01:46
    SERIN will in fact wait -- for something -- so if you're getting data when you don't expect it the output from your keypad is bouncing up and down and causing the BASIC Stamp to think that it's getting valid bits. Maybe the output of the keypad needs to be pulled one way or the other. Since your baudmode parameter indicates 2400 baud, true mode (for the BS2, BS2e, or BS2pe) then I suggest connecting a 10K resistor between pin 7 (SERIN pin) and Vdd.· This will hold that line high until the keypad actually pulls it low for a serial bit.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • NickNick Posts: 11
    edited 2005-05-01 03:47
    I fixed the problem. It was a short in the wire harness going from the LCD to the stamp.

    Thanks again guys.
Sign In or Register to comment.