c++ - ASM I/O pins HCS12 micro controller -
iam using hcs12 micro controller. following program have takes input on board keypad , displays letters on board lcd depending on key pressed (i attached portion of code dealing inputs / outputs, can attach rest if need easier on eyes way).
what rid of keypad being used inputs, , use sensor have sends active low signals though 3 separate pins instead. way in stead of having push keypad each time, whenever sensor reads 1 of readings (either porta1, 2 or 3) display correct letter.
the init_keypad function sets porta0-porta3 inputs.
in getkey function im not sure how change if statements read porta0-porta3 individualy
void init_keypad(void){ ddra = 0xf0; // pa7-pa4 output; pa3-pa0 input ddrb = 0xf0; pucr |= 1; // pupae =1 (enable pull-up on 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 }
let's assume you've read input porta variable we'll name input
.
in case, testing individual bits of input
looks like:
if (input & 1) { // bit 0 set } if (input & 2) { // bit 1 set } if (input & 4) { // bit 2 set }
Comments
Post a Comment