Beruflich Dokumente
Kultur Dokumente
#include<reg51.h>
sfr ROW=0x80; //assigning PORT-0 to read rows
sfr COL=0xA0; //assigning PORT-2 to read colomns
sfr ldata=0x90; //assigning PORT-1 for LCD data
sbit rs=P3^3;
sbit rw=P3^4;
sbit en=P3^5;
sbit busy=P2^7;
void main(void)
{
lcdcmd(0x38);
lcdcmd(0x0F);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x80);
printstring("Welcome Home");
msdelay(1000);
IE=0x81;
TCON=0x03;
while(1){
menu();
}
}
en=0;
}
/* checking LCD buffer for free */
void lcdready(void)
{
busy=1;
rs=0;
rw=1;
if(busy==1)
{
en=0;
msdelay(1);
en=1;
}
}
/* generating delay*/
void msdelay(unsigned int value)
{
unsigned int i,j;
for(i=0;i<value;i++)
for(j=0;j<100;j++);
}
void LCDclear(void)
{
lcdcmd(0x01);
}
int keypad()
{
unsigned char dat[4][4]={'7','8','9','%', // assigning key matrix
'4','5','6','*',
'1','2','3','-',
'C','0','=','+'};
unsigned char colloc,rowloc;
COL=0xFF;
ROW=0x00;
rs=0;
rw=0;
en=0;
busy=0;
/* setting LCD screen*/
ldata=0x00;
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x06);
while(1)
{
/* reading character from keyboard */
do
{
ROW=0x00;
colloc=COL;
colloc&=0x0F;
}while(colloc!=0x0F);
do
{
do
{
msdelay(25);
colloc=COL;
colloc&=0x0F;
}while(colloc==0x0F);
msdelay(25);
colloc=COL;
colloc&=0x0F;
}while(colloc==0x0F);
while(1)
{
ROW=0xFE;
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=0;
break;
}
ROW=0xFD;
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=1;
break;
}
ROW=0xFB;
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=2;
break;
}
ROW=0xF7;
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=3;
break;
}
}
if(colloc==0x0E)
return(dat[rowloc][0]);
else if(colloc==0x0D)
return(dat[rowloc][1]);
else if(colloc==0x0B)
return(dat[rowloc][2]);
else
return(dat[rowloc][3]);
}
}
void menu(void)
{
unsigned char userID[4]={'9','8','7','6'};
unsigned char PWD[4]={'1','2','3','4'};
unsigned char user_id[4]={'0','0','0','0'};
unsigned char password[4];
unsigned int i=0;
while(1)
{
LCDclear();
lcdcmd(0x80);
printstring("Enter UserID:");
lcdcmd(0xC0);
msdelay(200);
do
{
user_id[i]=keypad();
lcddata(user_id[i]);
i++;
msdelay(250);
}while(i!=4);
i=0;
if(userID[0]==user_id[0] && userID[1]==user_id[1] && userID[2]==user_id[2] &&
userID[3]==user_id[3])
{
LCDclear();
lcdcmd(0x80);
printstring("Enter Password:");
lcdcmd(0xC0);
i=0;
do
{
password[i]=keypad();
lcddata('*');
i++;
msdelay(200);
}while(i!=4);
i=0;
if(PWD[0] == password[0] && PWD[1] == password[1] && PWD[2] ==
password[2] && PWD[3] == password[3])
{
LCDclear();
lcdcmd(0x80);
printstring("Authunticated");
msdelay(1000);
LCDclear();
status();
}
else
{
LCDclear();
lcdcmd(0x80);
printstring("Access Denied");
msdelay(1000);
}
}
else
{
LCDclear();
lcdcmd(0x80);
printstring("Invalid UserID");
msdelay(1000);
}
}
}
break;
case 'C': LCDclear();
status();
break;
default : status();
break;
}
}