Discussion forum for the BasicX family of microcontroller chips.
|
Has anyone successfully written some simple code to read a 4 x 4 matrix keypad on a single pin. I'm about to start using the RC command and connecting the keypad between +5 and 0v with a string of equal value resistors. neil |
|
|
|
For a great serial keypad, go to www.nollet.com.au Ron will help you, we use his keypads in a commercial application, they're great. Chris ----- Original Message ----- From: neil jepsen <> To: <> Sent: Sunday, December 24, 2000 5:01 AM Subject: [BasicX] keypad > Has anyone successfully written some simple code to read a 4 x 4 > matrix keypad on a single pin. I'm about to start using the RC command > and connecting the keypad between +5 and 0v with a string of equal > value resistors. > neil |
|
Bob, I've got a matrixed keypad working, with 100% reliability. i had to connect the cap you showed to +5, to ground instead, and I've hacked your code around quite a bit, as my keypad was a 4 x 3 and the keys are not in stanadard positions. My code allows the use of any key arrangment, and uses (thanks to Tony) the 'select case' expression to sort out which key was pressed. Works very well, and is quite short and easy to follow. I'll put the code up if your'e interested. Thanks for your help. neil |
|
|
|
On Wed, 27 Dec 2000 19:18:35 +1300, you wrote:
>Bob, > I've got a matrixed keypad working, with 100% reliability. i >had to connect the cap you showed to +5, to ground instead, and I've >hacked your code around quite a bit, as my keypad was a 4 x 3 and the >keys are not in stanadard positions. My code allows the use of any key >arrangment, and uses (thanks to Tony) the 'select case' expression to >sort out which key was pressed. Works very well, and is quite short and >easy to follow. >I'll put the code up if your'e interested. >Thanks for your help. >neil Yes! Please do. grant |
|
Here Goes Grant. The keypad is connected as per Bob Goss: connect 1k from row 1 to row 2 " 1k from row 2 to row 3 " 1 k from row 3 to row 4 " row 4 to +5v " 3k9 from column 4 to column 3 " 3k9 from column 3 to column 2 " 3k9 from column 2 to column 1 " 1k5 and 100ohm in series from column 1 to BX24 input 15 " 0.047 cap from ground to junction of the 100 ohm and the 1k5 The code is as follows: '********************************************* 'Simple Serial Keypad decoder. * 'Written: N.M. Jepsen. Palmerston North. New Zealand * 'January 2001 * '********************************************* dim x as integer dim key as byte Sub Main() do readKP: call putpin(15,0) 'set pin low sleep(10) 'discharge cap x = RCtime(15,0) 'read RC time if (x<300) or (X>4000) then goto readKP 'filter any wild values end if call keypushed loop end sub '******************************** 'the following code filters the RC value. Slightly different values may be obtained depending 'on the value of the 0.047 used. Different keypad key arrangments will have different number order sub keypushed() debug.print "x=" & cstr(x) 'display RC value select case x case 300 to 400 key = 11 '* key case 500 to 600 key = 7 case 800 to 900 key = 4 case 1000 to 1100 key = 1 case 1250 to 1350 key = 0 case 1500 to 1600 key = 8 case 1750 to 1850 key = 5 case 2000 to 2100 key = 2 case 2200 to 2300 key = 12 '# key case 2475 to 2550 key = 9 case 2700 to 2800 key = 6 case 2950 to 3050 key = 3 case else debug.print "case error" end select debug.print "key = " & cstr (key) 'display key sleep(50) 'key repeat time end sub '************************************************************** Grant Baxter wrote: > On Wed, 27 Dec 2000 19:18:35 +1300, you wrote: > > > > >Bob, > > I've got a matrixed keypad working, with 100% reliability. > i > >had to connect the cap you showed to +5, to ground instead, and I've > >hacked your code around quite a bit, as my keypad was a 4 x 3 and the > > >keys are not in stanadard positions. My code allows the use of any > key > >arrangment, and uses (thanks to Tony) the 'select case' expression to > > >sort out which key was pressed. Works very well, and is quite short > and > >easy to follow. > >I'll put the code up if your'e interested. > >Thanks for your help. > >neil > > > > > Yes! Please do. > > grant > eGroups Sponsor [Click here to Win a 2001 Acura MDX] Click here to Win a 2001 Acura MDX [Non-text portions of this message have been removed] |
|
does anyone have code for the ede1144 chip? i have a 4x4 keypad hooked up to it and but i am not sure where i am supposed to start. i checked the files section and also on the internet. i can't seem to find any sample code for this. so if anyone could upload their file into files section or just email it to me. i would be greatful! conrad |
|
'Requires 24 BYTES Stack 'put in MAIN SUB 'PUBLIC KPIN as BYTE ' CALL OpenQueue(INBUF1,10) 'com1 buffer for keypad ' CALL OpenQueue(OUTBUF,0) 'No data out ' CALL OpenCom(1, 2400, INBUF1, OUTBUF) ' PUBLIC KEYPADSTACK(1 to 24) as BYTE ' CallTask "KeyPadTASK", KeyPadSTACK Sub KeyPadTASK() DIM LAST1 as BYTE DO LAST1=1 CALL WaitForInterrupt(bxPinLow) DO IF (StatusQueue(INBUF1))THEN CALL GetQueue(INBUF1,KPIN,1) ELSE LAST1 = LAST1 + 1 END IF LOOP UNTIL(LAST1 = 10) CALL SLEEP(0.0) LOOP End Sub KPIN will contain the ASC value of the ROW/COLUMN key as 0-9 A-F. The ASC value WILL NOT be what is printed on the KEYPAD you are using. Use the cross reference table I sent you. Use this snipit throughout you MAIN code to check for a KEYPRESS: IF (KPIN <> 0) THEN 'check for keypress CALL GOTKEY() 'keypad gave us a chr, lets look at it END IF This is my KEYPRESS processing Sub Routine, hack away... ************************************************************************* 'KEYPAD Process Routine. 'Routine handles keypresses on the fly. 'It calls the MENU SubRoutine if CLEAR is pressed. Public SUB GOTKEY() SELECT CASE KPIN CASE 70 'ENTER CALL LCDCLS(212) CASE 67 'UP ARROW KEY CALL LCD(CHR(254)&CHR(212)&"UP ARROW KEY ") CALL LCDCLS(212) IF(GETBIT(DISPLAY,0)=1)THEN CALL PUTBIT(DISPLAY,0,0) CALL PUTBIT(DISPLAY,1,1) ELSEIF(GETBIT(DISPLAY,1)=1)THEN CALL PUTBIT(DISPLAY,1,0) CALL PUTBIT(DISPLAY,2,1) ELSEIF(GETBIT(DISPLAY,2)=1)THEN CALL PUTBIT(DISPLAY,2,0) CALL PUTBIT(DISPLAY,3,1) ELSEIF(GETBIT(DISPLAY,3)=1)THEN CALL PUTBIT(DISPLAY,3,0) CALL PUTBIT(DISPLAY,0,1) END IF CASE 68 'DN ARROW KEY CALL LCD(CHR(254)&CHR(212)&"DN ARROW KEY ") CALL LCDCLS(212) IF(GETBIT(DISPLAY,3)=1)THEN CALL PUTBIT(DISPLAY,3,0) CALL PUTBIT(DISPLAY,2,1) ELSEIF(GETBIT(DISPLAY,2)=1)THEN CALL PUTBIT(DISPLAY,2,0) CALL PUTBIT(DISPLAY,1,1) ELSEIF(GETBIT(DISPLAY,1)=1)THEN CALL PUTBIT(DISPLAY,1,0) CALL PUTBIT(DISPLAY,0,1) ELSEIF(GETBIT(DISPLAY,0)=1)THEN CALL PUTBIT(DISPLAY,0,0) CALL PUTBIT(DISPLAY,3,1) END IF CASE 69 '2ND KEY DO CALL LCD(CHR(254)&CHR(212)&"RESET PROCESSOR ") SLEEP(256) CALL LCD(CHR(254)&CHR(212)&"<ENTER> to CONFIRM") SLEEP(256) CALL LCD(CHR(254)&CHR(212)&"<CLEAR> to ABORT ") SLEEP(256) LOOP UNTIL((KPIN=70) OR (KPIN=51)) IF(KPIN=51)THEN KPIN=0 CALL LCDCLS(212) ELSEIF(KPIN=70)THEN KPIN=0 CALL ResetProcessor() END IF CASE 66 'HELP KEY KPIN=0 CALL LCDCLS(212) IF(GETBIT(DISPLAY,7)=1)THEN CALL PUTBIT(DISPLAY,7,0) CALL LCD(CHR(254)&CHR(212)&"DEBUG OFF") ELSEIF(GETBIT(DISPLAY,7)=0)THEN CALL PUTBIT(DISPLAY,7,1) CALL LCD(CHR(254)&CHR(212)&"DEBUG ON ") END IF CALL LCDCLS(212) CASE 51 'CLEAR KEY KPIN=0 CMD="" CALL LCDCLS(212) CALL LCD(CHR(254)&CHR(212)) CALL LCD(CHR(254)&CHR(15)) DO SLEEP(0) SELECT CASE KPIN CASE 0 GOTO LOOP1 CASE 51 KPIN=0 CMD="MENU" CALL LCDCLS(212) CALL LCD(CHR(254)&CHR(212)&CMD) DO SLEEP(0) LOOP UNTIL((KPIN=70) OR (KPIN=51)) IF(KPIN=51)THEN CALL LCDCLS(212) CALL LCD(CHR(254)&CHR(12)) GOTO ENDSUB END IF KPIN=0 EXIT DO CASE 55, 48, 52, 56, 49, 53, 57, 50, 54, 65 SELECT CASE KPIN CASE 48 KP="1" CASE 52 KP="2" CASE 56 KP="3" CASE 49 KP="4" CASE 53 KP="5" CASE 57 KP="6" CASE 50 KP="7" CASE 54 KP="8" CASE 65 KP="9" CASE 55 KP="0" END SELECT CMD=CMD&KP KP="" KPIN=0 CALL LCD(CHR(254)&CHR(212)&CMD) IF(LEN(CMD)=6)THEN EXIT DO END IF END SELECT LOOP1: LOOP UNTIL(KPIN=70) KPIN=0 CALL LCD(CHR(254)&CHR(12)) CALL LCDCLS(212) ' STRING1=MID(CMD,1,1) ' IF(ASC(STRING1)=83)THEN ' STRING6=MID(CMD,4,3) ' CALL ValueS(STRING6, VBATT, CONFLAG) 'Convert 5 chr string to SINGLE ' IF (NOT CONFLAG) THEN 'Bad Convert - set error ' ErrorFlag = 9 ' CALL ERROR() ' GOTO ENDSUB ' END IF ' END IF ' IF(ASC(STRING1)=83)THEN ' CMD=MID(CMD,1,3) ' END IF CALL STRIPPROMPT(CMD) 'CALL LCD(CHR(254)&CHR(212)&"KP PROMPTIS="&CSTR(PROMPTIS)) 'CALL SLEEP(4.0) SELECT CASE PROMPTIS CASE 1098 '"stuffed" MENU command CALL MENU() CASE 245 IF((GETBIT(UPSTATUS,0)=1) AND (GETBIT(UPSTATUS,1)=0))THEN CALL Inverter(1,1) END IF CALL InverterStatus(1) IF(ErrorFlag <> 0) THEN 'ERROR if not able to issue "SMODE I" to UPS1 CALL ERROR() END IF CASE 248 IF((GETBIT(UPSTATUS,0)=1) AND (GETBIT(UPSTATUS,1)=1))THEN CALL Inverter(1,2) END IF CALL InverterStatus(1) IF(ErrorFlag <> 0) THEN 'ERROR if not able to issue "SMODE A" to UPS1 CALL ERROR() END IF CASE 247 IF((GETBIT(UPSTATUS,4)=1) AND (GETBIT(UPSTATUS,5)=0))THEN CALL Inverter(2,1) END IF CALL InverterStatus(2) IF(ErrorFlag <> 0) THEN 'ERROR if not able to issue "SMODE I" to UPS2 CALL ERROR() END IF CASE 250 IF((GETBIT(UPSTATUS,4)=1) AND (GETBIT(UPSTATUS,5)=1))THEN CALL Inverter(2,2) END IF CALL InverterStatus(2) IF(ErrorFlag <> 0) THEN 'ERROR if not able to issue "SMODE A" to UPS2 CALL ERROR() END IF CASE 123 'Here for setpoint processing CASE ELSE CALL LCD(CHR(254)&CHR(212)&"INVALID Command") CALL SLEEP(1.0) END SELECT END SELECT ENDSUB: KPIN=0 END SUB -----Original Message----- From: mixman1982 [mailto:] Sent: Thursday, August 22, 2002 9:33 PM To: Subject: [BasicX] keypad does anyone have code for the ede1144 chip? i have a 4x4 keypad hooked up to it and but i am not sure where i am supposed to start. i checked the files section and also on the internet. i can't seem to find any sample code for this. so if anyone could upload their file into files section or just email it to me. i would be greatful! conrad |
|
|
|
hey thanks a lot james i'll get to work on all that and see what i can make out of it. thanks! by the way how do you just come up with this stuff? haha. conrad --- In basicx@y..., "James R. Parish" <jparish@j...> wrote: > 'Requires 24 BYTES Stack > 'put in MAIN SUB > 'PUBLIC KPIN as BYTE > ' CALL OpenQueue(INBUF1,10) 'com1 buffer for keypad > ' CALL OpenQueue(OUTBUF,0) 'No data out > ' CALL OpenCom(1, 2400, INBUF1, OUTBUF) > ' PUBLIC KEYPADSTACK(1 to 24) as BYTE > ' CallTask "KeyPadTASK", KeyPadSTACK > > Sub KeyPadTASK() > DIM LAST1 as BYTE > > DO > LAST1=1 > CALL WaitForInterrupt(bxPinLow) > DO > IF (StatusQueue(INBUF1))THEN > CALL GetQueue(INBUF1,KPIN,1) > ELSE > LAST1 = LAST1 + 1 > END IF > LOOP UNTIL(LAST1 = 10) > CALL SLEEP(0.0) > LOOP > > End Sub > > KPIN will contain the ASC value of the ROW/COLUMN key as 0-9 A-F. The ASC > value WILL NOT be what is printed on the KEYPAD you are using. Use the > cross reference table I sent you. > > Use this snipit throughout you MAIN code to check for a KEYPRESS: > > IF (KPIN <> 0) THEN 'check for keypress > CALL GOTKEY() 'keypad gave us a chr, lets look at it > END IF > > This is my KEYPRESS processing Sub Routine, hack away... ********************************************************************* **** > 'KEYPAD Process Routine. > 'Routine handles keypresses on the fly. > 'It calls the MENU SubRoutine if CLEAR is pressed. > Public SUB GOTKEY() > > SELECT CASE KPIN > CASE 70 'ENTER > CALL LCDCLS(212) > CASE 67 'UP ARROW KEY > CALL LCD(CHR(254)&CHR(212)&"UP ARROW KEY ") > CALL LCDCLS(212) > IF(GETBIT(DISPLAY,0)=1)THEN > CALL PUTBIT(DISPLAY,0,0) > CALL PUTBIT(DISPLAY,1,1) > ELSEIF(GETBIT(DISPLAY,1)=1)THEN > CALL PUTBIT(DISPLAY,1,0) > CALL PUTBIT(DISPLAY,2,1) > ELSEIF(GETBIT(DISPLAY,2)=1)THEN > CALL PUTBIT(DISPLAY,2,0) > CALL PUTBIT(DISPLAY,3,1) > ELSEIF(GETBIT(DISPLAY,3)=1)THEN > CALL PUTBIT(DISPLAY,3,0) > CALL PUTBIT(DISPLAY,0,1) > END IF > CASE 68 'DN ARROW KEY > CALL LCD(CHR(254)&CHR(212)&"DN ARROW KEY ") > CALL LCDCLS(212) > IF(GETBIT(DISPLAY,3)=1)THEN > CALL PUTBIT(DISPLAY,3,0) > CALL PUTBIT(DISPLAY,2,1) > ELSEIF(GETBIT(DISPLAY,2)=1)THEN > CALL PUTBIT(DISPLAY,2,0) > CALL PUTBIT(DISPLAY,1,1) > ELSEIF(GETBIT(DISPLAY,1)=1)THEN > CALL PUTBIT(DISPLAY,1,0) > CALL PUTBIT(DISPLAY,0,1) > ELSEIF(GETBIT(DISPLAY,0)=1)THEN > CALL PUTBIT(DISPLAY,0,0) > CALL PUTBIT(DISPLAY,3,1) > END IF > CASE 69 '2ND KEY > DO > CALL LCD(CHR(254)&CHR(212)&"RESET PROCESSOR ") > SLEEP(256) > CALL LCD(CHR(254)&CHR(212)&"<ENTER> to CONFIRM") > SLEEP(256) > CALL LCD(CHR(254)&CHR(212)&"<CLEAR> to ABORT ") > SLEEP(256) > LOOP UNTIL((KPIN=70) OR (KPIN=51)) > > IF(KPIN=51)THEN > KPIN=0 > CALL LCDCLS(212) > ELSEIF(KPIN=70)THEN > KPIN=0 > CALL ResetProcessor() > END IF > CASE 66 'HELP KEY > KPIN=0 > CALL LCDCLS(212) > IF(GETBIT(DISPLAY,7)=1)THEN > CALL PUTBIT(DISPLAY,7,0) > CALL LCD(CHR(254)&CHR(212)&"DEBUG OFF") > ELSEIF(GETBIT(DISPLAY,7)=0)THEN > CALL PUTBIT(DISPLAY,7,1) > CALL LCD(CHR(254)&CHR(212)&"DEBUG ON ") > END IF > CALL LCDCLS(212) > CASE 51 'CLEAR KEY > KPIN=0 > CMD="" > CALL LCDCLS(212) > CALL LCD(CHR(254)&CHR(212)) > CALL LCD(CHR(254)&CHR(15)) > > DO > SLEEP(0) > SELECT CASE KPIN > CASE 0 > GOTO LOOP1 > CASE 51 > KPIN=0 > CMD="MENU" > CALL LCDCLS(212) > CALL LCD(CHR(254)&CHR(212)&CMD) > DO > SLEEP(0) > LOOP UNTIL((KPIN=70) OR (KPIN=51)) > IF(KPIN=51)THEN > CALL LCDCLS(212) > CALL LCD(CHR(254)&CHR(12)) > GOTO ENDSUB > END IF > KPIN=0 > EXIT DO > > CASE 55, 48, 52, 56, 49, 53, 57, 50, 54, 65 > SELECT CASE KPIN > CASE 48 > KP="1" > CASE 52 > KP="2" > CASE 56 > KP="3" > CASE 49 > KP="4" > CASE 53 > KP="5" > CASE 57 > KP="6" > CASE 50 > KP="7" > CASE 54 > KP="8" > CASE 65 > KP="9" > CASE 55 > KP="0" > END SELECT > > CMD=CMD&KP > KP="" > KPIN=0 > CALL LCD(CHR(254)&CHR(212)&CMD) > IF(LEN(CMD)=6)THEN > EXIT DO > END IF > END SELECT > > LOOP1: > LOOP UNTIL(KPIN=70) > KPIN=0 > > CALL LCD(CHR(254)&CHR(12)) > CALL LCDCLS(212) > > ' STRING1=MID(CMD,1,1) > ' IF(ASC(STRING1)=83)THEN > ' STRING6=MID(CMD,4,3) > ' CALL ValueS(STRING6, VBATT, CONFLAG) 'Convert 5 chr string to > SINGLE > ' IF (NOT CONFLAG) THEN 'Bad Convert - set > error > ' ErrorFlag = 9 > ' CALL ERROR() > ' GOTO ENDSUB > ' END IF > ' END IF > ' IF(ASC(STRING1)=83)THEN > ' CMD=MID(CMD,1,3) > ' END IF > > CALL STRIPPROMPT(CMD) > 'CALL LCD(CHR(254)&CHR(212)&"KP PROMPTIS="&CSTR(PROMPTIS)) > 'CALL SLEEP(4.0) > > SELECT CASE PROMPTIS > CASE 1098 > '"stuffed" MENU command > CALL MENU() > > CASE 245 > IF((GETBIT(UPSTATUS,0)=1) AND (GETBIT(UPSTATUS,1)=0))THEN > CALL Inverter(1,1) > END IF > CALL InverterStatus(1) > IF(ErrorFlag <> 0) THEN 'ERROR if not able to issue > "SMODE I" to UPS1 > CALL ERROR() > END IF > > CASE 248 > IF((GETBIT(UPSTATUS,0)=1) AND (GETBIT(UPSTATUS,1)=1))THEN > CALL Inverter(1,2) > END IF > CALL InverterStatus(1) > IF(ErrorFlag <> 0) THEN 'ERROR if not able to issue > "SMODE A" to UPS1 > CALL ERROR() > END IF > > CASE 247 > IF((GETBIT(UPSTATUS,4)=1) AND (GETBIT(UPSTATUS,5)=0))THEN > CALL Inverter(2,1) > END IF > CALL InverterStatus(2) > IF(ErrorFlag <> 0) THEN 'ERROR if not able to issue > "SMODE I" to UPS2 > CALL ERROR() > END IF > > CASE 250 > IF((GETBIT(UPSTATUS,4)=1) AND (GETBIT(UPSTATUS,5)=1))THEN > CALL Inverter(2,2) > END IF > CALL InverterStatus(2) > IF(ErrorFlag <> 0) THEN 'ERROR if not able to issue > "SMODE A" to UPS2 > CALL ERROR() > END IF > > CASE 123 'Here for setpoint processing > > CASE ELSE > CALL LCD(CHR(254)&CHR(212)&"INVALID Command") > CALL SLEEP(1.0) > > END SELECT > > END SELECT > > ENDSUB: > KPIN=0 > END SUB > -----Original Message----- > From: mixman1982 [mailto:catchya@s...] > Sent: Thursday, August 22, 2002 9:33 PM > To: basicx@y... > Subject: [BasicX] keypad > > does anyone have code for the ede1144 chip? i have a 4x4 keypad > hooked up to it and but i am not sure where i am supposed to start. > i checked the files section and also on the internet. i can't seem > to find any sample code for this. so if anyone could upload their > file into files section or just email it to me. i would be greatful! > > conrad |