基于80C51單片機的電子儲物柜系統
? ? ? ?電路描述:
安全是我們日常的生活中最關心的問題。 每個人都覺得安全問題是非常至關重要的,在家里的門和安全,可以盡可能多的安全。 為了對于門訪問安全因此,我們打算通過引進一個電子密碼鎖系統,該系統包括一個人得到一個訪問某些項目之前要輸入密碼的安全性,以及在家里,一個房間密碼鎖系統,不只是普通的單用戶密碼鎖系統,需要用戶插入已編程的代碼來訪問一個房間; 它是一個密碼鎖系統,有密碼而且可以啟用多個用戶訪問。
在基于51單片機的門儲物柜,只允許授權人員進入限制區(qū)域的門禁系統。 該系統由8位微控制器AT89C2051具有ROM的2K字節(jié)的程序存儲器完全控制。 該系統具有通過該密碼,可以通過它來輸入鍵盤。 當輸入的密碼與存儲在存儲器中的口令相等則門被打開。 如果我們輸入了錯誤的密碼超過三次,然后報警接通。
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;
}
}
責任編輯;zl
評論
查看更多