Iam using the HCS12 micro controller. The following program that I have takes the input from an on board keypad and displays letters to an on board LCD depending on which key is pressed (I only attached the portion of the code dealing with the inputs / outputs, i can attach the rest if need be but its easier on the eyes this way).
What I would like to do is to get rid of the keypad interface being used as inputs, and use a sensor that I have which sends active low signals though 3 separate pins instead. That way in stead of having to push the keypad each time, whenever the sensor reads a low signal (either PortA1, 2 or 3) it will display the correct letter.
The init_keypad function sets PortA0-PortA3 as inputs. In the getkey function im not sure how to change the if statements to read PortA0-PortA3 individually and check for the active low inputs.
void init_keypad(void){
DDRA = 0xf0; // PA7-PA4 output; PA3-PA0 input
DDRB = 0xf0;
PUCR |= 1; // PUPAE =1 (enable pull-up on all PORTA inputs)
}
char getkey(void){
PORTA = 0xe0; // selects row 0
if ((PORTA & 1) == 0){
cmdwrt(0x01);
delay(20);
if ((PORTA & 1) == 0) return('L');//true if '1' key still active after 20 ms
}
PORTA = 0xd0;
if ((PORTA & 1) == 0){
cmdwrt(0x01);
delay(20);
if ((PORTA & 1) == 0) return('S');//true if '1' key still active after 20 ms
}
PORTA = 0xb0;
if ((PORTA & 1) == 0){
cmdwrt(0x01);
delay(20);
if ((PORTA & 1) == 0) return('R');//true if '1' key still active after 20 ms
}