Tuesday, 22 September 2015

4x4 Keypad programming in ARM7(LPC2129/38)( text on LCD(using 4 data lines) according to buttons pressed )



#include<lpc21xx.h>
void delay();
void cmd(int);
void cmd1(int);
void data(char);
char keypad();
int main()
{
char k;
IO0DIR=0XFFFFC0FF;
IO1DIR=0XFFFFFFFF;
cmd(0x30);
cmd(0x30);
cmd(0x30);
cmd(0x20);
cmd1(0x28);
cmd1(0x01);
cmd1(0x06);
cmd1(0x0e);
cmd1(0x80);
while(1)
{
k=keypad();
if(k!='z')
data(k);
}
}
char keypad()
{
int e;
IO0CLR=0XFFFFFFFF;
IO0SET=0X0001C000;
e=IO0PIN&0X00003C00;
switch(e)
{
case 0x00001C00:
return '1';
break;
case 0x00002C00:
return '2';
break;
case 0x00003400:
return '3';
break;
case 0x00003800:
return '4';
break;
}

IO0CLR=0XFFFFFFFF;
IO0SET=0X0002C000;
e=IO0PIN&0X00003C00;
switch(e)
{
case 0x00001C00:
return '5';
break;
case 0x00002C00:
return '6';
break;
case 0x00003400:
return '7';
break;
case 0x00003800:
return '8';
break;
}

IO0CLR=0XFFFFFFFF;
IO0SET=0X00034000;
e=IO0PIN&0X00003C00;
switch(e)
{
case 0x00001C00:
return '9';
break;
case 0x00002C00:
return '0';
break;
case 0x00003400:
return 'a';
break;
case 0x00003800:
return 'b';
break;
}

IO0CLR=0XFFFFFFFF;
IO0SET=0X00038000;
e=IO0PIN&0X00003C00;
switch(e)
{
case 0x00001C00:
return 'c';
break;
case 0x00002C00:
return 'd';
break;
case 0x00003400:
return 'e';
break;
case 0x00003800:
return 'f';
break;

default:
return 'z';
break;
}
}

 void cmd(int b)
{
unsigned int s;
s=b&0xf0;
IO1SET=s<<16;
IO1CLR=0X000F0000;
IO1SET|=0X00080000;
delay();
IO1CLR=0X00080000;
IO1CLR=0XFFFFFFFF;
}

void cmd1(int a)
{
unsigned int s;
s=a&0xf0;
IO1SET=s<<16;
IO1CLR=0X000F0000;
IO1SET|=0X00080000;
delay();
IO1CLR=0X00080000;
IO1CLR=0XFFFFFFFF;


s=a&0x0f;
IO1SET=s<<20;
IO1CLR=0X000F0000;
IO1SET|=0X00080000;
delay();
IO1CLR=0X00080000;
delay();
IO1CLR=0XFFFFFFFF;
}

void data(char a)
{
char s;
s=a&0xf0;
IO1SET=s<<16;
IO1CLR=0X000F0000;
IO1SET|=0X000A0000;
delay();
IO1CLR=0X00080000;
IO1CLR=0XFFFFFFFF;


s=a&0x0f;
IO1SET=s<<20;
IO1CLR=0X000F0000;
IO1SET|=0X000A0000;
delay();
IO1CLR=0X00080000;
delay();
IO1CLR=0XFFFFFFFF;
}

void delay()
{
int i;
for(i=0;i<500000;i++);
}

No comments:

Post a Comment