You are on page 1of 2

KeyPad Interface

#include <lpc21xx.h> #include <uart.h>

int main(void) { unsigned int scanCode, rowCode, colCode, index; unsigned int arrayHex[]={0x7E, 0x7D, 0x7B, 0x77, 0xBE, 0xBD, 0xBB, 0xB7, 0xDE, 0xDD, 0xDB, 0xD7, 0xEE, 0xED, 0xEB, 0xE7}; unsigned int arrayCheckAscii[]={0x31, 0x32, 0x33, 0x65, 0x34, 0x35, 0x36, 0x66, 0x37, 0x38, 0x39, 0x67, 0x2A, 0x30, 0x23, 0x68};

uart_init();

IODIR0=0x3FC; IOCLR0=0x3FC;

while(1) { IODIR0=0x3C; // direction of rows are output and column as input IOCLR0=0x3C; // rows are grounded

colCode = IOPIN0 & 0x3C0; colCode=colCode>>2;

IODIR0=0x3C0; rowCode=(IOPIN0 & 0x03C); rowCode=rowCode>>2;

scanCode=rowCode|colCode; for(index=0; index<16; index++) { if(scanCode==arrayHex[index]) { break; } }

uart_tx(arrayCheckAscii[index]); delay(300000); }

You might also like