设计一楼层单元门禁系统,能实现楼层住户密码开锁或其它身份识别开锁,能显示操作状态,阻止陌生人进入,能输出报警。设计完整的电路原理图和编写相关程序。 用MCS-51系列单片机或其它CPU作为控制器设计完整的控制系统,包括以下内容: 用LCD1602显示或其它点阵液晶或用LED显示; 实现磁卡、IC卡、射频卡或其它方式任意1种输入; 有密码输入按键; 有声音及报警输出; 当断电时能维持24小时正常工作。 外部220V电源(开关电源)供电; 用PROTEUS仿真其中一个功能。
单片机源程序如下:
- #include "reg52.h"
- #include "LCD1602.h"
- #define uchar unsigned char
- #define uint unsigned int
- unsigned char k;
- uchar pic;
- uchar k;
- uchar X;
- uchar keycount;
- //uchar keyprocesstime;
- uint Key_Time;
- uchar flashtime;
- uint PLcount;
- uchar table11[4]={0};
- uchar table1count;
- bit keyflag;
- bit gonengflag;
- bit pic3flag;
- bit pic4flag;
- bit pic5flag;
- bit pic11flag;
- bit pic55flag;
- uint pic3count;
- uint pic4count;
- uint pic5count;
- sbit JDQ = P2^3;
- sbit BEEP = P2^4;
- sbit LED = P2^5;
- void delay(uint n) //延时程序
- {
- uchar i,j;
- for(i=n;i>0;i--)
- for(j=112;j>0;j--);
- }
- void Display(void)
- {
- uchar i;
- switch(pic)
- {
- case 1: //显示正常界面,时间
- LCDDispString(0,1," TANLIJUAN ");
- LCDDispString(0,2,"Please input num");
-
- break;
- case 2: //显示第一段波形调整界面
- LCDDispString(0,1,"Please Input ");//显示字符串
- LCDDispString(0,2,"num ");
- break;
- case 3: //显示第二段波形调整界面
- LCDDispString(0,1," Please wait ");
- LCDDispString(0,2," ........... ");
- pic3flag = 1;
- break;
- case 4: //显示第三段波形调整界面
- LCDDispString(0,1," Sorry ");
- LCDDispString(0,2," num error ");
- pic4flag = 1;
- break;
- case 5: //显示第四段波形调整界面
- LCDDispString(0,1," Right ");
- LCDDispString(0,2," You are welcome ");
- pic5flag = 1;
- break;
- }
- }
- /****************************************************/
- /* 4*4键盘读取程序 */
- /****************************************************/
- uchar GetKey ( )//键盘扫描函数,用于识别哪一个键按下,并读取键值
- {
- uchar X,Y,Z;
- P1 = 0xf0; //先对P1置数 行扫描
- if(P1!=0xf0) //判断是否有键按下
- {
- delay(50); //延时,软件去干扰
- if(P1!=0xf0) //确认按键按下X = P1;
- {
- X=P1&0xf0; //保存行扫描时有键按下时状态
- P1=0x0f; //列扫描
- Y=P1&0x0f; //保存列扫描时有键按下时状态
- Z=X|Y; //取出键值
- switch ( Z ) //判断键值(那一个键按下)
- {
- case 0x7e: k=1; break;
- case 0xbe: k=2; break;
- case 0xde: k=3; break;
- case 0x7d: k=4; break;
- case 0xbd: k=5; break;
- case 0xdd: k=6; break;
- //case 0xed: k=8; break;
- case 0x7b: k=7; break;
- case 0xbb: k=8; break;
- case 0xdb: k=9; break;
- //case 0xeb: k=12; break;
- case 0x77: k=0; break;
- case 0xee: k=13; break;//DEL
- case 0xb7: k=14; break;//CALL
- case 0xd7: k=15; break;//CANCEL
- case 0xe7: k=16; break;//ENTER
- }
- if(k<=9)
- {
- keyflag = 1;
- }
- else
- {
- gonengflag = 1;
- }
- }
- }
- }
- void Keyprocess(void) //键盘处理
- {
- switch (pic) //判断键值(那一个键按下)
- {
- case 1: //开机界面
- switch(k)
- {
- case 14:
- pic = 2;
- Display();
- keycount = 0;
- break;
- }
- break;
- case 2://第一段波形设置界面
- if((keyflag==1)&(table1count<4))
- {
- LCDDispNum(8+table1count,2,k);
- table11[table1count] = k;
- table1count++;
- }
- switch(k)
- {
- case 13://删除
- table1count--;
- if(table1count>=0)
- {
- LCDDispChar(8+table1count,2,0x04);
- }
- break;
- case 15:
- pic = 1;
- Display();
- keycount = 0;
- table1count = 0;
- break;
-
- case 16:
- if(1<=table11[0]<=4)
- {
- if(table11[1]==0)
- {
- if(1<=table11[2]<=4)
- {
- pic = 3;
- pic3flag = 1;
- Display();
- keycount = 0;
- table1count = 0;
- }
- else
- {
- pic = 4;
- pic4flag = 1;
- Display();
- keycount = 0;
- table1count = 0;
- BEEP = 1;
- LED = 1;
- }
- }
- else
- {
- pic = 4;
- pic4flag = 1;
- Display();
- keycount = 0;
- table1count = 0;
- BEEP = 1;
- LED = 1;
- }
- }
- else
- {
- pic = 4;
- pic4flag = 1;
- Display();
- keycount = 0;
- table1count = 0;
- BEEP = 1;
- LED = 1;
- }
- //JDQ = 1;
- break;
- }
- break;
- case 3:
- switch(k)
- {
- case 14:
- pic = 2;
- Display();
- keycount = 0;
- break;
- case 15:
- pic = 1;
- Display();
- keycount = 0;
- table1count = 0;
- break;
- }
- break;
- case 4:
- switch(k)
- {
- case 14:
- pic = 2;
- Display();
- keycount = 0;
- break;
- case 15:
- pic = 1;
- Display();
- keycount = 0;
- table1count = 0;
- break;
- }
- break;
- case 5:
- switch(k)
- {
- case 14:
- pic = 2;
- Display();
- keycount = 0;
- break;
- case 15:
- pic = 1;
- Display();
- keycount = 0;
- table1count = 0;
- break;
- }
- break;
- }
- }
- //
- void main(void)
- {
- pic = 1;
- LCDInit();//lcd初始化
- TMOD = 0x11;
- TH1 = 0xf8;
- TL1 = 0xcc;
- P0 = 0xff;
- TR1 = 1;
- ET1 = 1;
- EA=1;
- JDQ = 0;
- BEEP = 0;
- LED = 0;
- Display();
- while(1)
- {
- //Display();
- if(keyflag|gonengflag)
- {
- Keyprocess();
- keyflag = 0;
- gonengflag = 0;
- }
- if(pic11flag==1)
- {
- pic11flag = 0;
- pic = 1;
- Display();
- }
- if(pic55flag==1)
- {
- pic55flag = 0;
- pic = 5;
- Display();
- }
- if(pic3flag==1)
- {
- delay(5000);
- pic = 5;
- Display();
- }
- }
- }
- void T1_time (void) interrupt 3 using 2
- {
- TH1 = 0xf8;
- TL1 = 0xcc;
- Key_Time++;
- if(Key_Time == 250)
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
门禁设计系统.rar
(101.64 KB, 下载次数: 62)
|