4x4 Keypad C++
4x4 Keypad C++
h>
#define port P1
#define delay(200)
sfr data=0xA0;
sbit RS=P1^0;
sbit RW=P1^1;
sbit En=P1^2;
void delay(unsigned int sec)
{
int i,j;
for(i=0;i<sec;i++)
for(j=0;j<200;j++);
}
void lcd_comm(char t)
{
data=t;
RS=0;
RW=0;
EN=1;
delay(2);
EN=0;
}
void lcd_data(char u)
{
data=u;
RS=1;
RW=0;
EN=1;
delay(2);
EN=0;
}
lcd_init(unsigned char)
{
lcd_comm(0x38);
lcd_comm(0x0F);
lcd_comm(0x01);
lcd_comm(0x82);
lcd_comm(0x06);
}
void check_for_open_keys(void)
{
P1=0x00H;
P2=0x;
x=P2&(0x0F);
if(x==0x0F)
{
delay(1);
if(x==0x0F)
return(1);
else return (0);
}
else
return (0);
}
void check_key_pressed()
{
P1=0x0Eh;
x=P2&0x0F;
if(x==0x07)
{
delay(1);
}
if(x==0x07)
{
return (30H);
}
else
continue;
if(x==0x0B)
{
delay(1);
}
if(x==0x0B)
{
return (31H);
}
else
continue;
if(x=0x0D)
{
delay(1);
}
if(x=0x0D)
{
return (32H);
}
else
continue;
if(x=0x0E)
{
delay(1);
}
if(x=0x0E)
{
return (33H);
}
else
continue;
}
P1=0x0Dh;
x=P2&0x0F;
{
if(x==0x07)
{
delay(1);
}
if(x==0x07)
{
return (34H);
}
else
continue;
if(x==0x0B)
{
delay(1);
}
if(x==0x0B)
{
return (35H);
}
else
continue;
if(x=0x0D)
{
delay(1);
}
if(x=0x0D)
{
return (36H);
}
else
continue;
if(x=0x0E)
{
delay(1);
}
if(x=0x0E)
{
return (37H);
}
else
continue;
}
P1=0x0Dh;
x=P2&0x0F;
{
if(x==0x07)
{
delay(1);
}
if(x==0x07)
{
return (38H);
}
else
continue;
if(x==0x0B)
{
delay(1);
}
if(x==0x0B)
{
return (35H);
}
else
continue;
if(x=0x0D)
{
delay(1);
}
if(x=0x0D)
{
return (36H);
}
else
continue;
if(x=0x0E)
{
delay(1);
}
if(x=0x0E)
{
return (37H);
}
else
continue;
}
P1=0x07h;
x=P2&0x0F;
if(x==0x07)
{
delay(1);
}
if(x==0x07)
{
return (30H);
}
else
continue;
if(x==0x0B)
{
delay(1);
}
if(x==0x0B)
{
return (31H);
}
else
continue;
if(x=0x0D)
{
delay(1);
}
if(x=0x0D)
{
return (32H);
}
else
continue;
if(x=0x0E)
{
delay(1);
}
if(x=0x0E)
{
return (33H);
}
else
continue;
}
}
void main()
{
char a;
a=check_key_pressed();
}