PDA

View Full Version : Programming help with keypad interfacing to the LCD



Gabe
08-22-2005, 12:47 PM
Hi Guys

I was wondering how do I get my LCD to output the word "Keypress" whenever a key is pressed on the Keypad that is interfaced to it. Everything I inserted seems to always get the whole thing stuck.
Here are my codes:


DATA "Hello, This is the LCD."
Initlcd:
LCDCMD Lcd_pin,32 'sets lcd in 4 bit mode
PAUSE 1000
FOR temp = 0 TO 2
LCDCMD 0,48
PAUSE 1
NEXT
LCDCMD Lcd_pin,40 'sets lcd to 2 linemode with 5x8 font
LCDCMD Lcd_pin,12 'turns on display with no cursor
LCDCMD Lcd_pin,6 'set to auto-increment cursor
LCDCMD Lcd_pin,1 'clears display' - --[ Main Routine ]----------------------------------------------------
start:
FOR temp = 0 TO 22
READ temp, char
IF temp = 19 THEN Next_line
out:
LCDOUT 0,non_op,[char]
PAUSE 100 ' This number ajest the rate of displaying the text
NEXT again:
GOSUB keyScan
IF press = 0 THEN again
DEBUG "key pressed = ", HEX key,CR
LCDCMD Lcd_pin,1 'This is the line I inserted
LCDOUT 0,0,["Keypress"] 'This is the line I inserted
PAUSE 100
press = 0
GOTO again

Subroutine keyScan basically scans for the keypress on the 4 x 4 matrix keypad and output the value on to the debug window. Any help appreciated.

Thanks in advance,
Gab

Chris Savage
08-22-2005, 09:17 PM
Gabe,

·· What values is your keypress supposed to return when you press keys?· Are you sure that routine is working, since you didn't include it?· Also, your "again:" label is in a bad spot, but I didn't know if that was just from the copy and paste, or what.



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

Tom-Matrix Orbital
08-23-2005, 03:29 AM
What type of display are you using?

Chris Savage
08-23-2005, 05:05 AM
Tom,

·· The commands he's using correspond to a Parallel LCD Display.



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

Gabe
08-23-2005, 01:25 PM
Hi Chris,

Heres my keyScan subroutine:


keyScan:
AUXIO
FOR row = 0 TO 3 ' Scan rows one at a time.
LOW row ' Output a 0 on current row.
key = ~cols ' Get the inverted state of column bits.
key = NCD key ' Convert to bit # + 1 with NCD.
IF key <> 0 THEN push ' No high on cols? No key pressed.
INPUT row ' Disconnect output on row.
NEXT ' Try the next row.
db = 0 ' Reset the debounce bit.
RETURN ' Return to program.
push:
IF db = 1 THEN done ' Already responded to this press, so done.
db = 1: press = 1 ' Set debounce and keypress flags.
key = (key-1)+(row*4) ' Add column (0-3) to row x 4 (0,4,8,12).
' Key now contains 0-15, mapped to this arrangement:
' 0 1 2 3
' 4 5 6 7
' 8 9 10 11
' 12 13 14 15
' A lookup table is translates this to match the actual
' markings on the key caps.
LOOKUP key,[1,2,3,15,4,5,6,14,7,8,9,13,10,0,11,12],key
done:
INPUT row ' Disconnect output on row.
RETURN ' Return to program.

Currently, my program would display out the values of the keypress in the Debug window. E.g. when I pressed the number 7 button on the keypad, the Debug window will output "Keypress is: 7".

With that done, I want to try outputting the word "Keypress" onto the·LCD im using,(which is 2 x 20 by the way)·when ANY keypress on the keypad is detected. Preferably I would like the LCD to output the values of the keypress along with the Debug window,· but I would like to get the "Keypress" output·right first before I go ahead with it.

Regards,

Gab

Chris Savage
08-23-2005, 10:07 PM
Gabe,

·· Have you verified that the LCD output works by itself?· I would write a small separate program which outputs text to the LCD to verify it is working.· Now that I see what you're trying to do, it seems like it should work.· Unless your LCD isn't working.· Let me ask you this.· Do you see the correct output on the DEBUG screen?· Try putting a DEBUG statement after the LCD commands to see if the program is getting past them.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

Tom-Matrix Orbital
08-24-2005, 03:16 AM
Oops my mistake.

Chris Savage
08-24-2005, 05:31 AM
Tom,

·· No mistake...I think you guys have Parallel Displays too...But the LCD commands only work on Parallel Displays, that's how I knew.· Don't know the brand, but that part shouldn't matter.· I'm just unclear if the display is properly initializing at all...

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

Gabe
08-29-2005, 01:56 PM
Hi Chris,

Sorry for the slow reply. Computer was kinda dodgy these few days but got it sorted out now. Anyway, I played with the device again and realised I forgotten to put in a MAINIO command before sending out a command to the LCD (which was actually
connected to the MAIN I/O pins). The keys are on AUXIO, thus need the switching command. Anyway, thanks for your time.

Regards,
Gabe