microcontroller password system

#include< reg52.h>
sbit r0=P2^0; sbit r1=P2^1; sbit r2=P2^2; sbit r3=P2^3; sbit c0=P2^5; sbit c1=P2^6;
sbit c2=P2^7; sbit en=P3^6; sbit rs=P3^5; sbit rw=P3^7; sbit lock=P3^0;
char t1[]="Enter PIN:";
char t2[]="Access Granted";
char t3[]="Access Denied";
char pin[]="1234";
char pinEntered[4];
unsigned int m = 0;
unsigned int flag = 0;

void delay(unsigned int no)
{
unsigned int i,j;
for(j=0;j<=no;j++) for(i=0;i<=10;i++);
}

void lcdcmd(unsigned int command){
P1=command; rw=0; rs=0; en=0; delay(1000); en=1; delay(1000); en=0;
}

void lcddata(char data1)
{
P1=data1; rw=0; rs=1; en=0; delay(1000); en=1; delay(1000); en=0;
}
void lcdint(){
lcdcmd(0x30); delay(1000); lcdcmd(0x30); delay(1000); lcdcmd(0x30); delay(1000);
lcdcmd(0x30); delay(1000); lcdcmd(0x30); delay(1000); lcdcmd(0x38); delay(1000);
lcdcmd(0x01); delay(1000); lcdcmd(0x0F); delay(1000); lcdcmd(0x80); delay(1000);
}

char keypad()
{
char c='a';
while(c!='s'){
r0=0;r1=1;r2=1;r3=1;
if(c0==0){lcddata('1');P0=0xF0;delay(10000);c='s';return '1';}
if(c1==0){lcddata('2');P0=0xF0;delay(10000);c='s';return '2';}
if(c2==0){lcddata('3');P0=0xF0;delay(10000);c='s';return '3';}

r0=1;r1=0;r2=1;r3=1;
if(c0==0){lcddata('4');P0=0xF0;delay(10000);c='s';return '4';}
if(c1==0){lcddata('5');P0=0xF0;delay(10000);c='s';return '5';}
if(c2==0){lcddata('6');P0=0xF0;delay(10000);c='s';return '6';}

r0=1;r1=1;r2=0;r3=1;
if(c0==0){lcddata('7');P0=0xF0;delay(10000);c='s';return '7';}
if(c1==0){lcddata('8');P0=0xF0;delay(10000);c='s';return '8';}
if(c2==0){lcddata('9');P0=0xF0;delay(10000);c='s';return '9';}

r0=1;r1=1;r2=1;r3=0;
//if(c0==0){lcddata('*');P0=0xF0;delay(10000);c='s';return '1';}
if(c1==0){lcddata('0');P0=0xF0;delay(10000);c='s';return '0';}
// if(c2==0){lcddata('#');P0=0xF0;delay(10000);c='s';return '1';}
}
}

void main()
{
unsigned int i=0;
P1=0x00; P2=0xF0; P3=0x00;
lcdint();
while(1){
i=0;
while(t1[i]!='\0')
{
lcddata(t1[i]);
i++;
}
lock=0;
lcdcmd(0xC0);

for(i=0;i<=3;i++)
pinEntered[i] =keypad();
i=0;
lcdcmd(0x01);

if(pinEntered[0]==pin[0])
{ i++;
if(pinEntered[1]==pin[1])
{
if(pinEntered[2]==pin[2])
{
if(pinEntered[3]==pin[3])
{
lock=1; i=0;
while(t2[i]!='\0')
{
lcddata(t2[i]);
i++;
}i=0;
}
}
}
}else{ i=0;
while(t3[i]!='\0')
{
lcddata(t3[i]);
i++;
} i=0; }

if(i!=0)
{
i=0;
while(t3[i]!='\0')
{
lcddata(t3[i]);
i++;
}
}
delay(1000000);
lcdcmd(0x01);
lcdcmd(0x80);
i=0;
} }
what is your question exactly ?
Topic archived. No new replies allowed.