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.

PIC18F4520 4x4 Keypad Scanning Process

Status
Not open for further replies.

symphony888

Newbie level 5
Joined
Nov 28, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,467
I'm currently trying to type out a code that can scan the keypad for buttons that are being pressed. It is attached to a 74C922 Encoder.
The rows and columns have been shrink down to only 5 pins which are labelled as D C B A, D being the MSB.

I'm using RC0,RC1,RC2 and RC3 for D C B A respectively and RD0 for the Data Available.

I'm having some problems on how to figure out a program to scan the keys that are pressed.

I've come with a small program but it is way too long.

Code:
char key;
if(PORTDbits.RD0 == 1)
{
if(PORTC == 0b00000000)
{
key = '1';
}else if(PORTC == 0b00000001)
{
key = '2';
}

As I'm not using RC7,RC6,RC5 and RC4 how do I type out a code that only scans for the ports that I'm using - RC0,RC1,RC2 and RC3.

Also if I were to continue this program it will be really long as I have to scan from 0000 to 1111 for the keys. Is there any other ways that I can shorten the program?
 

Hi,

By using just 3 more pins you can easily scan your keypad direct from the 4520 - is it worth using another chip ?
 

You are not really scanning the keys, just reading the output of the 74C922. As wp100 points out it is easy to do without an external interface but if you want to do it the way you show, this should be simpler:

char key;
if(PORTDbits.RD0 == 1)
{
key = PORTC & 0x0F;
}

Brian.
 

The target board that was given to me is included with the encoder.

Do you mind explaining why key = PORTC & 0x0F; ?
This will be interfaced with an LCD.
 

Not according to your original post, you said the lower bits of PORTC were the inputs from the 74C922. When you logic AND the value in the port you keep bits which are 1 in the 0x0F and zero the others so the result is only the lower 4 bits. The value 'key' will be the result from the 74C922 only, any other bits in PORTC will be ignored.

Brian.
 

Hmm. So in that case, I can't use that code to link with an LCD code?
Or is that code still possible? When I check if the Data Available is high, it will start checking the DCBA and it will output the key corresponding with the binary codes.
 

I think a full schematic is needed. In principle there is no problem driving an LCD and reading the keypad at the same time and on the same pins as long as you ensure the micro and the 74C922 don't both produce output at the same time. What you haven't made clear is how the LCD is connected and why you think it may not work.

The 74C922 does all they key handling for you, all you have to do it monitor it for the signal saying a key is pressed (DATA AVAILABLE) then read the DCBA pins into your program. Depending on your program structure you may then have to wait for DATA AVAILABLE to say the key is released before reading it again and also you may have to drive the /OUTPUT ENABLE pin if it clashes with your LCD signals.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top