Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] Problem interfacing self made matrix keypad

Status
Not open for further replies.

b.heuju

Junior Member level 2
Joined
Dec 17, 2013
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Nepal
Activity points
168
I am trying to interface matrix keypad. I made my own having 5 buttons (3 rows and 2 columns).
Like this:

...D0 D1 D2
D3 * * *
D4 * *

(D3, D0 = LEFT)
(D3, D2 = RIGHT)

I only need 5 keys, so I left the part (D4, D2).
The 3 columns are connected to pins D0-D2 (starting from left) and the rows are connected to D3-D4 (starting from top).

I understood the way of scanning the key pressed and applied it. And it works for first row. What I did was,
D3 and D4 as o/p.
D0, D1, D2 as i/p.

I made pin D3 high, and checked for D0, D1, D2. The code I used is mentioned below (without the CLEARBIT line).

Code:
uint8_t getKEY()
{	
	SETBIT(PORTD, PIND3);
	if (PIND & (1<<PIND0))
	{
		return LEFT;
	}
	if (PIND & (1<<PIND2))
	{
		return RIGHT;
	}
	CLEARBIT(PORTD, PIND3);
}

Note: This is not the complete code.
This function is called repeatedly for scanning the keys.

The problem that occured was, I had to use CLEARBIT(PORTD, PIND3) to reset the D3 pin to then make pin D4 high. But when I use CLEARBIT(PORTD, PIND3) the LEFT key does not work only the RIGHT key works. When I remove the CLEARBIT(PORTD, PIND3) line from the code, then both LEFT and RIGHT work perfectly. But this causes a problem, I can't scan for the next row because both D3 and D4 would be high without clearing pin D3. Also I am required to use pull down resistors at pins D0, D1, D2. It would not work without them.

What could be the problem? What am I doing wrong? Is there any other better way to scan the keys?

Thank You !
 

Hi
For scanning keypad you atleast need a set of pull ups or pull down, atleat inside your controller but without it, It wont be reliable.

In your case you will need two resistors.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top