电路描述:
安全是我们日常的生活中最关心的问题。 每个人都觉得安全问题是非常至关重要的,在家里的门和安全,可以尽可能多的安全。 为了对于门访问安全因此,我们打算通过引进一个电子密码锁系统,该系统包括一个人得到一个访问某些项目之前要输入密码的安全性,以及在家里,一个房间密码锁系统,不只是普通的单用户密码锁系统,需要用户插入已编程的代码来访问一个房间; 它是一个密码锁系统,有密码而且可以启用多个用户访问。
在基于51单片机的门储物柜,只允许授权人员进入限制区域的门禁系统。 该系统由8位微控制器AT89C2051具有ROM的2K字节的程序存储器完全控制。 该系统具有通过该密码,可以通过它来输入键盘。 当输入的密码与存储在存储器中的口令相等则门被打开。 如果我们输入了错误的密码超过三次,然后报警接通。
LCD的数据引脚连接到P1口和RS,R / W,E引脚连接到P0.2,P0.3,P0.4。 L293D采用旋转电机打开和关闭更衣室。 A 4 * 3键盘用于输入数字0到9,“*”,“#”。 有一个系统菜单,包含了开放式储物柜三个按钮,重设密码,并关闭了更衣室。
code:
#include《 reg51.h 》
#define col P2
#define row P3
sbit m1=P3^4;
sbit m2=P3^5;
sbit bu=P0^1;
sbit rs=P0^2;
sbit rw=P0^3;
sbit en=P0^4;
sbit start=P0^5;
sbit rst=P0^6;
sbit mp=P0^7;
sfr lcddata=0x90;
void delay(int a)
{
int i,j;
for(i=0;i for(j=0;j《1100;j++);
}
void command(unsigned char s) //初始化LCD的
{
lcddata=s;
rs=0;
rw=0;
en=1;
delay(5);
en=0;
}
void lcddisplaydata(unsigned char s) // LCD的数据写入
{
lcddata=s;
rs=1;
rw=0;
en=1;
delay(8);
en=0;
}
void displaydata(unsigned char *word)
{
int x;
for(x=0;word[x]!=0;x++) //LCD的数据写入
{
lcddisplaydata(word[x]);
}
}
unsigned char array[3][4]={‘0′,’1′,’2′,’3′,
‘4’,’5′,’6′,’7′,
‘8’,’9′,’*’,’#’};
int n=0;
int m=0;
int i,p,q,r;
void main()
{
unsigned char colloc, rowloc;
unsigned char array1[4];
unsigned char array2[4]={‘3′,’1′,’1′,’2′};
unsigned char array3[4];
LOCKER1:
col=0xFF;
row=0x00;
m1=0;
m2=0;
bu=0;
mp=1;
p=0;
q=0;
r=0;
m=0;
start=1;
rst=1;
command(0x01);
command(0x38);
command(0x0C);
command(0x84);
displaydata(“PRESS KEY”);
command(0xC0);
displaydata(“FROM SYSTEM MENU”);
while(1)
{
if(start==0)
{
p=1;
goto LOCKER2;
}
else if(rst==0)
{
q=1;
goto LOCKER3;
}
}
LOCKER2:
n=0;
command(0x01);
command(0x82);
delay(10);
displaydata(“Enter Your”);
command(0xC3);
displaydata(“Password”);
delay(80);
command(0x01);
command(0x80);
goto LOCKER5;
LOCKER3:
n=0;
command(0x01);
command(0x82);
delay(10);
displaydata(“Enter Current”);
command(0xC4);
displaydata(“Password”);
delay(80);
command(0x01);
command(0x80);
goto LOCKER5;
LOCKER4:
n=0;
m=0;
command(0x01);
command(0x83);
delay(10);
displaydata(“Enter new”);
command(0xC3);
displaydata(” Password”);
delay(80);
command(0x01);
command(0x80);
q=2;
goto LOCKER5;
LOCKER5:
col=0xFF;
while(1)
{
do
{
row=0x00;
colloc=col;
colloc &=0x0f;
}while(colloc!=0x0f);
do
{
colloc=col;
colloc &=0x0f;
}while(colloc==0x0f);
while(1)
{
row=0x0E;
colloc=col;
colloc &=0x0f;
if(colloc!=0x0f)
{
rowloc=0;
break;
}
row=0x0D;
colloc=col;
colloc &=0x0f;
if(colloc!=0x0f)
{
rowloc=1;
break;
}
row=0x0LOCKER11;
colloc=col;
colloc &=0x0f;
if(colloc!=0x0f)
{
rowloc=2;
break;
}
}
if(p==1)
{
if(colloc==0x0E)
{
array1[n]=array[rowloc][0];
n++;
goto LOCKER6;
}
else if(colloc==0x0D)
{
array1[n]=array[rowloc][1];
n++;
goto LOCKER6;
}
else if(colloc==0x0B)
{
array1[n]=array[rowloc][2];
n++;
goto LOCKER6;
}
else if(colloc==0x07)
{
array1[n]=array[rowloc][3];
n++;
goto LOCKER6;
}
}
else if(q==1)
{
if(colloc==0x0E)
{
array1[n]=array[rowloc][0];
n++;
goto LOCKER7;
}
else if(colloc==0x0D)
{
array1[n]=array[rowloc][1];
n++;
goto LOCKER7;
}
else if(colloc==0x0B)
{
array1[n]=array[rowloc][2];
n++;
goto LOCKER7;
}
else if(colloc==0x07)
{
array1[n]=array[rowloc][3];
n++;
goto LOCKER7;
}
}
else if(r==2)
{
if(colloc==0x0E)
{
array1[n]=array[rowloc][0];
n++;
goto LOCKER11;
}
else if(colloc==0x0D)
{
array1[n]=array[rowloc][1];
n++;
goto LOCKER11;
}
else if(colloc==0x0B)
{
array1[n]=array[rowloc][2];
n++;
goto LOCKER11;
}
else if(colloc==0x07)
{
array1[n]=array[rowloc][3];
n++;
goto LOCKER11;
}
}
else if(q==2)
{
if(colloc==0x0E)
{
array2[n]=array[rowloc][0];
n++;
goto LOCKER9;
}
else if(colloc==0x0D)
{
array2[n]=array[rowloc][1];
n++;
goto LOCKER9;
}
else if(colloc==0x0B)
{
array2[n]=array[rowloc][2];
n++;
goto LOCKER9;
}
else if(colloc==0x07)
{
array2[n]=array[rowloc][3];
n++;
goto LOCKER9;
}
}
else if(q==3)
{
if(colloc==0x0E)
{
array3[n]=array[rowloc][0];
n++;
goto LOCKER8;
}
else if(colloc==0x0D)
{
array3[n]=array[rowloc][1];
n++;
goto LOCKER8;
}
else if(colloc==0x0B)
{
array3[n]=array[rowloc][2];
n++;
goto LOCKER8;
}
else if(colloc==0x07)
{
array3[n]=array[rowloc][3];
n++;
goto LOCKER8;
}
}
}
LOCKER6:
if(n《4)
{
lcddisplaydata(‘*’);
goto LOCKER5;
}
else if(n==4)
{
lcddisplaydata(‘*’);
delay(50);
if(array1[1]==array2[1]&&array1[2]==array2[2]&&array1[3]==array2[3]&&array1[0]==array2[0])
{
command(0x01);
command(0x80);
displaydata(“RIGHT PASSWORD”);
delay(50);
m=0;
n=0;
goto LOCKER14;
}
else
{
command(0x01);
command(0x80);
displaydata(“WRONG PASSWORD”);
delay(50);
goto LOCKER15;
}
}
LOCKER7:
if(n《4)
{
lcddisplaydata(‘*’);
goto LOCKER5;
}
else if(n==4)
{
lcddisplaydata(‘*’);
delay(50);
if(array1[1]==array2[1]&&array1[2]==array2[2]&&array1[3]==array2[3]&&array1[0]==array2[0])
{
goto LOCKER4;
}
else
{
goto LOCKER12;
}
}
LOCKER8:
if(n《4)
{
lcddisplaydata(‘*’);
goto LOCKER5;
}
else if(n==4)
{
lcddisplaydata(‘*’);
delay(50);
if(array3[1]==array2[1]&&array3[2]==array2[2]&&array3[3]==array2[3]&&array3[0]==array2[0])
{
command(0x01);
command(0x80);
delay(10);
displaydata(“New Password has”);
command(0xC3);
displaydata(“been set”);
delay(100);
command(0x01);
m=0;
goto LOCKER1;
}
else
{
goto LOCKER13;
}
}
LOCKER9:
if(n《4)
{
lcddisplaydata(‘*’);
goto LOCKER5;
}
else if(n==4)
{
lcddisplaydata(‘*’);
delay(50);
m=0;
goto LOCKER10;
}
LOCKER10:
{
command(0x01);
command(0x80);
delay(10);
displaydata(“Conform Password”);
delay(50);
command(0x01);
q=3;
n=0;
goto LOCKER5;
}
LOCKER11:
if(n《4)
{
lcddisplaydata(‘*’);
goto LOCKER5;
}
else if(n==4)
{
lcddisplaydata(‘*’);
delay(50);
if(array1[1]==array2[1]&&array1[2]==array2[2]&&array1[3]==array2[3]&&array1[0]==array2[0])
{
bu=0;
goto LOCKER1;
}
else
{
goto LOCKER16;
}
}
LOCKER12:
{
command(0x01);
command(0x80);
m++;
if(m《3)
goto LOCKER3;
else
bu=1;
delay(500);
bu=0;
goto LOCKER1;
}
LOCKER13:
{
command(0x01);
command(0x80);
m++;
if(m《3)
goto LOCKER10;
else
goto LOCKER1;
}
LOCKER14:
{
m1=1;
m2=0;
delay(125);
m1=0;
m2=0;
while(mp!=0);
m1=0;
m2=1;
delay(125);
m1=0;
m2=0;
delay(100);
command(0x01);
command(0x80);
goto LOCKER1;
}
LOCKER15:
{
command(0x01);
command(0x80);
m++;
if(m《3)
goto LOCKER2;
else
bu=1;
r=2;
p=0;
q=0;
n=0;
goto LOCKER5;
}
LOCKER16:
{
command(0x01);
command(0x80);
n=0;
goto LOCKER5;
}
}