In SX Microcontrollers, SX/B Compiler and SX-Key Tool, tdg8934 wrote: I bought an old Radio Shack Matrix keypad (3x5) (p/n: 270-215) and got it to work modifying the SX/B Help file on the 4x4 Matrix Keypad example - to use it as a 3x5 matrix and then displaying the results on a 4x20 serial LCD by Parallax. It works for the most part and I will modify it some more later to add a shift type buttons to allow for alphabetic characters. Anyway, what I am seeing is that when you hit a key, it usually displays on the LCD 2-3 of the characters that was hit. Is there a debounce way to fix this or do I just need to add a longer Delay? ' ========================================================================= ' ' File...... LCD_SERIAL_RevF_4x20_Keyboard.SXB ' Purpose... SX/B Programming for Parallax Serial LCD (No BS2 Required) ' Author.... Timothy Gilmore ' E-mail.... [url=tdg8934@comcast.net]tdg8934@comcast.net[/url] ' Started... November 12, 2005 ' Updated... February 5, 2006 ' ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' This program allows the user to control a Parallax Serial LCD ' 4 rows x 20 characters Backlit (#27979) with a 3x5 matrix keypad ' using an "SX28 microcontroller" with Parallax SX/B Basic Compiler ' without using a Basic Stamp 2 (BS2) microcontroller by Parallax. ' ' 3 Baud rates available of 19200, 9600 and 2400 are allowed via LCD ' switch settings & firmware settings (e.g. LcdBaud19200, LcdBaud9600 or LcdBaud2400) ' ' Connections: RX --> SX28 pin RA.0 (or what ever other output pin) ' 5V --> Vdd (+5 VDC) ' GND -> Vss (Gnd) ' ' The Keypad is a Radio Shack 3x5 matrix keypad (270-215) assigned to: ' ' C1 C2 C3 ' ' R1 [ 1 ] [ 2 ] [ 3 ] (5) ' ' R2 [ 4 ] [ 5 ] [ 6 ] (7) ' ' R3 [ 7 ] [ 8 ] [ 9 ] (8) ' ' R4 [ A ] [ 0 ] [ B ] (2) ' ' R5 [ C ] [ D ] [ E ] (1) ' ' (3) (4) (6) ' ' It uses an 8 pin connector as listed above in parenthesis. ' C1 (5),C2 (4) and C3 (6) are wired to RC.7,RC.6 and RC.5 respectively. ' 10K resistors are also tied to each RC.7, RC.6 and RC.5 pin and then connected to ground. ' ' 220 ohm resistors come out of RC.0, RC.1, RC.2, RC.3 and RC.4 and then tie into ' R5 (1), R4 (2), R3 (8), R2 (7) and R1 (5) to complete the keyboard circuit. ' ' See the SX/B 4x4 Matrix Keypad Help circuit for a similar example. ' ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 ' Use 4 MHz Resonator ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- TxPin VAR RA.0 ' RA.0 pin used Keys VAR RC ' keyboard scan port TRIS_Keys VAR TRIS_C Col1 VAR Keys.7 ' column inputs Col2 VAR Keys.6 Col3 VAR Keys.5 ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- Yes CON 1 No CON 0 LcdBaud CON "T19200" ' Baud rate = 19200 -> SW1 ON, SW2 ON 'LcdBaud CON "T9600" ' Baud rate = 9600 -> SW1 OFF, SW2 ON 'LcdBaud CON "T2400" ' Baud rate = 2400 -> SW1 ON, SW2 OFF ' LCD Test Mode -> SW1 OFF, SW2 OFF LcdDispCC0 CON $00 ' display custom char 0 LcdDispCC1 CON $01 ' display custom char 1 LcdDispCC2 CON $02 ' display custom char 2 LcdDispCC3 CON $03 ' display custom char 3 LcdDispCC4 CON $04 ' display custom char 4 LcdDispCC5 CON $05 ' display custom char 5 LcdDispCC6 CON $06 ' display custom char 6 LcdDispCC7 CON $07 ' display custom char 7 LcdBkSpc CON $08 ' move cursor left LcdRt CON $09 ' move cursor right LcdLF CON $0A ' move cursor down 1 line LcdCls CON $0C ' clear LCD (need 5 ms delay) LcdCR CON $0D ' move to position 0 of next line LcdBLon CON $11 ' backlight on LcdBLoff CON $12 ' backlight off LcdOff CON $15 ' LCD off LcdOn1 CON $16 ' LCD on; no crsr, no blink LcdOn2 CON $17 ' LCD on; no crsr, blink on LcdOn3 CON $18 ' LCD on; crsr on, no blink LcdOn4 CON $19 ' LCD on; crsr on, blink on LcdLine0Pos0 CON $80 ' move to line 0, position 0 LcdLine0Pos1 CON $81 ' move to line 0, position 1 LcdLine0Pos2 CON $82 ' move to line 0, position 2 LcdLine0Pos3 CON $83 ' move to line 0, position 3 LcdLine0Pos4 CON $84 ' move to line 0, position 4 LcdLine0Pos5 CON $85 ' move to line 0, position 5 LcdLine0Pos6 CON $86 ' move to line 0, position 6 LcdLine0Pos7 CON $87 ' move to line 0, position 7 LcdLine0Pos8 CON $88 ' move to line 0, position 8 LcdLine0Pos9 CON $89 ' move to line 0, position 9 LcdLine0Pos10 CON $8A ' move to line 0, position 10 LcdLine0Pos11 CON $8B ' move to line 0, position 11 LcdLine0Pos12 CON $8C ' move to line 0, position 12 LcdLine0Pos13 CON $8D ' move to line 0, position 13 LcdLine0Pos14 CON $8E ' move to line 0, position 14 LcdLine0Pos15 CON $8F ' move to line 0, position 15 LcdLine0Pos16 CON $90 ' move to line 0, position 16 LcdLine0Pos17 CON $91 ' move to line 0, position 17 LcdLine0Pos18 CON $92 ' move to line 0, position 18 LcdLine0Pos19 CON $93 ' move to line 0, position 19 LcdLine1Pos0 CON $94 ' move to line 1, position 0 LcdLine1Pos1 CON $95 ' move to line 1, position 1 LcdLine1Pos2 CON $96 ' move to line 1, position 2 LcdLine1Pos3 CON $97 ' move to line 1, position 3 LcdLine1Pos4 CON $98 ' move to line 1, position 4 LcdLine1Pos5 CON $99 ' move to line 1, position 5 LcdLine1Pos6 CON $9A ' move to line 1, position 6 LcdLine1Pos7 CON $9B ' move to line 1, position 7 LcdLine1Pos8 CON $9C ' move to line 1, position 8 LcdLine1Pos9 CON $9D ' move to line 1, position 9 LcdLine1Pos10 CON $9E ' move to line 1, position 10 LcdLine1Pos11 CON $9F ' move to line 1, position 11 LcdLine1Pos12 CON $A0 ' move to line 1, position 12 LcdLine1Pos13 CON $A1 ' move to line 1, position 13 LcdLine1Pos14 CON $A2 ' move to line 1, position 14 LcdLine1Pos15 CON $A3 ' move to line 1, position 15 LcdLine1Pos16 CON $A4 ' move to line 1, position 16 LcdLine1Pos17 CON $A5 ' move to line 1, position 17 LcdLine1Pos18 CON $A6 ' move to line 1, position 18 LcdLine1Pos19 CON $A7 ' move to line 1, position 19 LcdLine2Pos0 CON $A8 ' move to line 2, position 0 LcdLine2Pos1 CON $A9 ' move to line 2, position 1 LcdLine2Pos2 CON $AA ' move to line 2, position 2 LcdLine2Pos3 CON $AB ' move to line 2, position 3 LcdLine2Pos4 CON $AC ' move to line 2, position 4 LcdLine2Pos5 CON $AD ' move to line 2, position 5 LcdLine2Pos6 CON $AE ' move to line 2, position 6 LcdLine2Pos7 CON $AF ' move to line 2, position 7 LcdLine2Pos8 CON $B0 ' move to line 2, position 8 LcdLine2Pos9 CON $B1 ' move to line 2, position 9 LcdLine2Pos10 CON $B2 ' move to line 2, position 10 LcdLine2Pos11 CON $B3 ' move to line 2, position 11 LcdLine2Pos12 CON $B4 ' move to line 2, position 12 LcdLine2Pos13 CON $B5 ' move to line 2, position 13 LcdLine2Pos14 CON $B6 ' move to line 2, position 14 LcdLine2Pos15 CON $B7 ' move to line 2, position 15 LcdLine2Pos16 CON $B8 ' move to line 2, position 16 LcdLine2Pos17 CON $B9 ' move to line 2, position 17 LcdLine2Pos18 CON $BA ' move to line 2, position 18 LcdLine2Pos19 CON $BB ' move to line 2, position 19 LcdLine3Pos0 CON $BC ' move to line 2, position 0 LcdLine3Pos1 CON $BD ' move to line 2, position 1 LcdLine3Pos2 CON $BE ' move to line 2, position 2 LcdLine3Pos3 CON $BF ' move to line 2, position 3 LcdLine3Pos4 CON $C0 ' move to line 2, position 4 LcdLine3Pos5 CON $C1 ' move to line 2, position 5 LcdLine3Pos6 CON $C2 ' move to line 2, position 6 LcdLine3Pos7 CON $C3 ' move to line 2, position 7 LcdLine3Pos8 CON $C4 ' move to line 2, position 8 LcdLine3Pos9 CON $C5 ' move to line 2, position 9 LcdLine3Pos10 CON $C6 ' move to line 2, position 10 LcdLine3Pos11 CON $C7 ' move to line 2, position 11 LcdLine3Pos12 CON $C8 ' move to line 2, position 12 LcdLine3Pos13 CON $C9 ' move to line 2, position 13 LcdLine3Pos14 CON $CA ' move to line 2, position 14 LcdLine3Pos15 CON $CB ' move to line 2, position 15 LcdLine3Pos16 CON $CC ' move to line 2, position 16 LcdLine3Pos17 CON $CD ' move to line 2, position 17 LcdLine3Pos18 CON $CE ' move to line 2, position 18 LcdLine3Pos19 CON $CF ' move to line 2, position 19 LcdDefCC0 CON $F8 ' define custom char 0 LcdDefCC1 CON $F9 ' define custom char 1 LcdDefCC2 CON $FA ' define custom char 2 LcdDefCC3 CON $FB ' define custom char 3 LcdDefCC4 CON $FC ' define custom char 4 LcdDefCC5 CON $FD ' define custom char 5 LcdDefCC6 CON $FE ' define custom char 6 LcdDefCC7 CON $FF ' define custom char 7 ' Also display ASCII Characters $20 to $7F (exception of $5C '\' and $7E '~') ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- theKey VAR Byte ' from keypad, 1 - 15 row VAR Byte ' keyboard scan row temp1 VAR Byte ' work vars temp2 VAR Byte ' ========================================================================= PROGRAM Start ' ========================================================================= ' Matrix to remap keypad values ReMap: DATA "1", "2", "3" DATA "4", "5", "6" DATA "7", "8", "9" DATA "A", "0", "B" DATA "C", "D", "E" ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- SEROUTSXB SUB 1 GETKEY SUB ' get key from pad DELAY SUB 1, 2 ' delay in milliseconds ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: HIGH TxPin PAUSE 100 Main: SEROUTSXB LCDBLon ' Turn on the Backlight (Backlight model only) theKey = GETKEY ' get a key IF theKey.5 = 0 THEN ' was a key pressed? READ ReMap + theKey, theKey ' yes, remap keypad DELAY 100 SEROUTSXB theKey ' transmit the byte to the LCD ENDIF GOTO Main ' ------------------------------------------------------------------------- ' Subroutine Code ' ------------------------------------------------------------------------- SEROUTSXB: temp1 = __PARAM1 ' Capture the passed byte SEROUT TxPin, LcdBaud, temp1 ' Tx Byte RETURN ' return to caller ' Use: aByte = GETKEY ' -- scans keyboard and places key value into 'aByte' GETKEY: temp1 = 0 ' reset keyboard value row = 5 ' scan 5 rows Keys = %00010000 ' activate first row TRIS_Keys = %11100000 ' refresh IO state DO WHILE row > 0 IF Col1 = Yes THEN EXIT ' check buttons on column INC temp1 ' update key value IF Col2 = Yes THEN EXIT INC temp1 IF Col3 = Yes THEN EXIT INC temp1 Keys = Keys >> 1 ' select next row DEC row LOOP RETURN temp1 ' Use: DELAY base {, multiplier} ' -- pause for 'base' * (optional) 'multiplier' milliseconds DELAY: ' delay x { * y } ms temp1 = __PARAM1 IF __PARAMCNT = 1 THEN temp2 = 1 ELSE temp2 = __PARAM2 ENDIF IF temp1 > 0 THEN IF temp2 > 0 THEN PAUSE temp1 * temp2 ENDIF ENDIF RETURN ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=108212 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)