Keypad

Thread Starter

MkRacer220

Joined Dec 4, 2008
4
I'm currently setting up the same circuit with a 3x4 keypad. You mention the resistors to pull the other pins high. With a typical keypad -> micro input, do these resistors go in series with the input lines, or in parrallel with ground? I am just testing my keypad scan program, but the button presses are not registering.
Thanks for the help...sorry to highjack
 

Thread Starter

MkRacer220

Joined Dec 4, 2008
4
Thanks for the move...better in the long run.....i should have known anyway.

My circuit is an 89C51RB2 micro. P1.1 pin -> CD4050 buffer -> keypad column 1. The 4 rows then go to p2 of the micro with no resistors.

When I execute the code (below), the P3.6 stays low. It only goes high when all of the buttons are pressed on the keypad. It always goes go KEY1 subroutine.

Guess the issue I'm having is my keypad program?

;test for keypad lock
;P1 = COLUMNS
;P2 = ROWS
;P3 = OUTPUT

.EQU COUNT1, 50H
.EQU COUNT2, 52H

CLR P1
CLR P2
CLR P3.7
CLR P3.6

BEG:
MOV P1, #00H
MOV P2, #00H
MOV COUNT1, #00H
MOV COUNT2, #00H

PRESS:
MOV TEMP1, A
MOV A, #00H

SETB P1.1 ;set p1.1 high
MOV P2, #0FH ;set p2 for input
MOV A, P2 ;get p2 input
CLR P1.1 ;clear p1.1
ANL A, #0FH ;mask upper bits of A
JNZ KEY1 ;jump if a key pressed

SETB P1.2
MOV P2, #0FH
MOV A, P2
CLR P1.2
ANL A, #0FH
JNZ KEY2

SETB P1.3
MOV P2, #0FH
MOV A, P2
CLR P1.3
ANL A, #0FH
JNZ KEY3

MOV A, TEMP1
SETB P3.6
SJMP PRESS

KEY1:
SETB P3.7
CLR P3.6
MOV COUNT1, #40H
DC1: DJNZ COUNT1, DC1
LJMP PRESS

KEY2:
;SETB P3.7
MOV COUNT2, #40H
DC2: DJNZ COUNT2, DC2
LJMP PRESS

KEY3:
;SETB P3.7
MOV COUNT1, #40H
DC3: DJNZ COUNT1, DC3
LJMP PRESS


Thanks for the help.
 
Last edited:

Thread Starter

MkRacer220

Joined Dec 4, 2008
4
I dont have access to a schematic drawing program as I'm doing this at home. The micro works as I can toggle output pins to drive LEDs, plus I can program it.

The issue is when the scan cycles through, it alwas goes into KEY1 subroutine, meaning that the accumulator is always non-zero.

P1.1, P1.2 and P1.3 are the columns (respectivly). They go to the input of a CD4050 buffer (non-inverting, which I dont think I need). The output from the CD4050 goes to the column input for the keypad (simple 7 pin keypad). The rows then connect to P2.0, P2.1, P2.2 and P2.3.
 

beenthere

Joined Apr 20, 2004
15,819
Do you know how your keyboard works? It should be that a keypress will make a contact to one column and one row. To scan it, the uC will have to pull each column low by setting an output pin low, and look for one of the rows going low at the same time. Repeat with each column (or row - machs nichts).

Just so you understand, all outputs and inputs have to be high when nothing is going on. You set each output to the keyboard low to scan it. A low on an input pin identifies the key pressed. But the output has to be expressly set back high before the next row or column gets tested.

It would be helpful to have a weak pullup on each of the inputs - about 47K to Vcc.

The CD4050 is not particularly helpful.
 
Top