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?