Keypad with latched switches

Thread Starter

Malsch

Joined Mar 19, 2011
23
Hi,

i am using the 8051 and am having trouble with scanning a 2x8 keypad. This is due to the fact that the switches are latched ones (push to make switch). Also more than one switch can be pressed at one time.

The code written, scans each column (the column which is being scanned is set to low) and when a switch is pressed, the output pin is set to low when the column is scanned. The problem arises when more than one switch is pressed in each column. I think this is because when more than one switch is pressed, both the input and the output pins are then set to low due to the two (or more) columns being shorted together. If anyone can help, it would be greatly appreciated. Thank you

Code:

#define Rows P1
#define Columns P2
#define DigitalOP P3

void main(void)
{
while(1)
{
Columns=0xFE;
BPMDelay(1000);
Columns=0xFD;
BPMDelay(1000);
Columns=0xFB;
BPMDelay(1000);
Columns=0xF7;
BPMDelay(1000);
}
}
 

Attachments

ErnieM

Joined Apr 24, 2011
8,377
I don't know 8051's but I know micros. Didn't look at your code but you have both a hardware and a software issue here.

Hardware because there is at least 1 condition where there is no way to get a solid read of the keys: that is when NONE of them is pressed. Any given pin for input will not be driven, so you can't tell what you will read. I would fix that by adding pull up resistors on all 9 pins going to the keyboard. Your micro may even have those as an internal option.

To sense keys make P1.1 and .2 inputs while you drive the P2.0-7 as outputs. To start make P2.0 low, and P2.1 to P2.7 high. That way, the top left switch is the only switch that can make P1.0 go low. Same with bottom left switch and P1.1. You can then scan down and drive one P2 pin high while the others are low to read all 16 buttons.
 

Thread Starter

Malsch

Joined Mar 19, 2011
23
i have done some more research and it seems that i need to use diodes so that the inputs does not influence the outputs. i have applied them (screenshot) but unfortunately, the simulation still doesnt work so far...
 

Attachments

stahta01

Joined Jun 9, 2011
133
i have done some more research and it seems that i need to use diodes so that the inputs does not influence the outputs. i have applied them (screenshot) but unfortunately, the simulation still doesnt work so far...
I would have tried the diodes going the opposite direction from the way you showed. But, I would use a low to scan the keys; you might be using a high.

Tim S.
 
Top