#include<reg51.h>
#include"lcd_display.h"
void column1();
void column2();
void column3();
void resetPassword();
void getNewPassword();
char getkey();
sbit c1=P0^0;
sbit c2=P0^1;
sbit c3=P0^2;
sbit r1=P0^3;
sbit r2=P0^4;
sbit r3=P0^5;
sbit r4=P0^6;
sbit reset_password=P1^2;
sbit ON=P1^3;
char reset_code[3]={'9','9','9'},password[6];
int i=0,count=0,danger=0;
int col,row;
char num[4][3]={{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}};
void main()
{
char c;
c1=c2=c2=1;
r1=r2=r3=r4=0;
reset_password=ON=1;
rs=en=0;
P2=0x00;
TMOD=0x01;
lcd_init();
while(1)
{
while(!reset_password) // loop for resetting the password
{ //if owner enters an correct ID
lcd_cmd(0x01);
lcd_dataS("Welcome Owner");
lcd_cmd(0xc0);
lcd_dataS("enter ID-");
count=0;
for(i=0;i<3;i++) //i<3 because reset_code is only 3characters
{
while(c1==1 && c2==1 && c3==1); //wait for the key to be pressed
c=getkey();
lcd_data(c);
if(c==reset_code[i]) count++; //count everytime entered key matches
} //with stored key
if(count==3) //if enters correctly COUNT will be 3
{
lcd_cmd(0x01);
resetPassword();
lcd_dataS("Password resetd");
getNewPassword();
}
else
{
lcd_cmd(0x01);
lcd_dataS("wrong code");
}
} //end of first while
while(!ON)
{
lcd_cmd(0x01);
lcd_dataS("welcome");
lcd_cmd(0xc0);
lcd_dataS("enter P-");
count=0;
for(i=0;i<6;i++) //i<6 because password is 6 characters wide
{
while(c1==1 && c2==1 && c3==1);
c=getkey();
lcd_data(c);
if(c==password[i])
count++; //count everytime entered key matches
}
if(count==6) //count will be 6 if entered password is correct
{
lcd_cmd(0x01);
lcd_dataS("welcome Boss");
lcd_cmd(0xc0);
lcd_dataS("Doors Opened");
count=0;
delay(10);
}
else
{
danger++; //everytime password is entered worng increment 'danger'
lcd_cmd(0x01);
lcd_dataS("wrong Password");
}
if (danger==4) //if danger count reaches 4
{ //here i just displayed the INTRUDER msg on the lcd
//here you can send a msg to owner by interfacing gsm
//or you can sound an buzzer
lcd_cmd(0x01);
lcd_dataS("intruder intruder");
danger=0;
delay(10);
}
} //end of second while loop
} //end of superloop
} //end of main
void getNewPassword()
{
i=0;
lcd_cmd(0x01);
lcd_dataS("enter New paswrd");
lcd_cmd(0xc0);
for(i=0;i<6;i++)
{
while(c1==1 && c2==1 && c3==1);
password[i]=getkey();
lcd_data(password[i]);
}
lcd_cmd(0x01);
lcd_dataS("password changed");
lcd_cmd(0xc0);
lcd_dataS("successfully");
}
void resetPassword()
{
int j;
for(j=0;j<6;j++)
password[j]='\0';
}
char getkey()
{
if(c1==0 || c2==0 || c3==0)
{
if(c1==0)
{
column1();
while(!c1);
col=0;
}
if(c2==0)
{
column2();
while(!c2);
col=1;
}
if(c3==0)
{
column3();
while(!c3);
col=2;
}
}
return num[row][col];
}
void column1()
{
r1=r2=r3=r4=1;
r1=0;
if(c1==0)
row=0;
r1=1;r2=0;
if(c1==0)
row=1;
r1=1;r2=1;r3=0;
if(c1==0)
row=2;
r1=1;r2=1;r3=1;r4=0;
if(c1==0)
row=3;
r1=r2=r3=r4=0;
}
void column2()
{
r1=r2=r3=r4=1;
r1=0;
if(c2==0)
row=0;
r1=1;r2=0;
if(c2==0)
row=1;
r1=1;r2=1;r3=0;
if(c2==0)
row=2;
r1=1;r2=1;r3=1;r4=0;
if(c2==0)
row=3;
r1=r2=r3=r4=0;
}
void column3()
{
r1=r2=r3=r4=1;
r1=0;
if(c3==0)
row=0;
r1=1;r2=0;
if(c3==0)
row=1;
r1=1;r2=1;r3=0;
if(c3==0)
row=2;
r1=1;r2=1;r3=1;r4=0;
if(c3==0)
row=3;
r1=r2=r3=r4=0;
}
Thursday, March 1, 2012
Security Door project Program for 8051
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment