/*
developed by S4silver
license type - open source
created on - 11/12/2014
modified on - 11/14/2014
modification details - refactored
developer - Frank Hust Jincson
contact mail id - silverembeddedsolutions@gmail.com
web link - http://s4silver.blogspot.in/p/programmers-colony.html
*/
#include <lpc214x.h>
unsigned int row, coll;
void delay(void)
{ unsigned int i;
for(i = 0; i <0xFF;i++);
}
void Send_Data (int data)
{
while (!(U0LSR & 0x20));
U0THR = data;
return;
}
void inituart(void)
{
PINSEL0 = 0x00000005; /* Enable RxD1 and TxD1 of UART0*/
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U0DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U0LCR = 0x03; /* DLAB = 0 */
}
void findrow(void)
{
IO1SET = 0x000F0000;
IO1CLR = 0x00010000;
if((IO1PIN & 0x00700000) != 0x00700000)
row = 0;
IO1SET = 0x000F0000;
IO1CLR = 0x00020000;
if((IO1PIN & 0x00700000) != 0x00700000)
row = 1;
IO1SET = 0x000F0000;
IO1CLR = 0x00040000;
if((IO1PIN & 0x00700000) != 0x00700000)
row = 2;
IO1SET = 0x000F0000;
IO1CLR = 0x00080000;
if((IO1PIN & 0x00700000) != 0x00700000)
row = 3;
}
void findcoll(void)
{
IO1CLR = 0x000F0000;
if((IO1PIN & 0x00700000) == 0x00600000)
coll = 0;
else if((IO1PIN & 0x00700000) == 0x00500000)
coll = 1;
else if((IO1PIN & 0x00700000) == 0x00300000)
coll = 2;
}
void main(void)
{
unsigned char keypad[4][3] = {'1','2','3','4','5','6','7','8','9','*','0','#'};
inituart();
IO1DIR = 0x000F0000; //p1.16 to p1.19 rows setas output port IO1CLR = 0x000F0000;
while(1)
{
while((IO1PIN & 0x00700000) == 0x00700000); while((IO1PIN & 0x00700000) != 0x00700000)
{
findrow();
findcoll();
Send_Data(keypad[row][coll]);
}
}
}
No comments:
Post a Comment