电子密码锁源程序代码

上传人:kms****20 文档编号:41057463 上传时间:2018-05-28 格式:DOC 页数:18 大小:47KB
返回 下载 相关 举报
电子密码锁源程序代码_第1页
第1页 / 共18页
电子密码锁源程序代码_第2页
第2页 / 共18页
电子密码锁源程序代码_第3页
第3页 / 共18页
电子密码锁源程序代码_第4页
第4页 / 共18页
电子密码锁源程序代码_第5页
第5页 / 共18页
点击查看更多>>
资源描述

《电子密码锁源程序代码》由会员分享,可在线阅读,更多相关《电子密码锁源程序代码(18页珍藏版)》请在金锄头文库上搜索。

1、电子密码锁源程序代码电子密码锁源程序代码1、可设置 4 位密码2、用户可自行设定和修改密码3、若密码错误,报警 5S,连续错 3 次,报警 1 分钟4、锁由继电器模拟#include unsigned char ps=1,2,3,4,5; /设定密码unsigned char code dispbit=0xfe,0xfd,0xfb,0xf7, 0xef,0xdf,0xbf,0x7f; unsigned char code dispcode=0x3f,0x06,0x5b,0x4f,0x66, 0x6d,0x7d,0x07,0x7f,0x6f, /数字 09 0x77,0x7c,0x39,0x5e

2、,0x79,0x71, /字母 AF0x00,0x40,0x73,0xff; /字符 -P8.unsigned char dispbuf8=18,16,16,16,16,16,16,16; unsigned char dispcount; /显示计数unsigned char flashcount; /闪烁计数 unsigned char temp; /临时变量unsigned char key; /按键unsigned char keycount; /按键计数unsigned char pslen=5; /密码长度unsigned char getps6; /得到的密码bit keyover

3、flag; /密码输入超位bit errorflag; /错误标志位bit rightflag; / 正确标志位unsigned int second3; unsigned int aa,bb; unsigned int cc; bit okflag; bit alarmflag; /报警标志bit hibitflag; /高位unsigned char oka,okb; void main(void) unsigned char i,j; TMOD=0x01; TH0=(65536-500)/256; /TH0 初始化TL0=(65536-500)%256; /TL0 初始化TR0=1; E

4、T0=1; EA=1; while(1) P3=0xff; /P3 赋值 255P3_4=0; temp=P3; temp=temp if (temp!=0x0f) for(i=10;i0;i-) for(j=248;j0;j-); temp=P3; temp=temp if (temp!=0x0f) temp=P3; temp=temp switch(temp) case 0x0e: key=7; break; case 0x0d: key=8; break; case 0x0b: key=9; break; case 0x07: key=10; break; temp=P3; / P1_1

5、=P1_1; if(key=0) keyoverflag=1;/key overflow else if(key=12)/delete key if(keycount0) keycount-; getpskeycount=0; /最近 1 次输入的数值清 0dispbufkeycount+1=16; /? else keyoverflag=1; /未输入密码按功能键,报错 else if(key=15)/enter key if(keycount!=pslen) /密码输入出错 errorflag=1; rightflag=0; second3=0; / else for(i=0;i0;i-)

6、 for(j=248;j0;j-); temp=P3; temp=temp if (temp!=0x0f) temp=P3; temp=temp switch(temp) case 0x0e: key=4; break; case 0x0d: key=5; break; case 0x0b: key=6; break; case 0x07: key=11; break; temp=P3; / P1_1=P1_1; if(key=0) keyoverflag=1;/key overflow else if(key=12)/delete key if(keycount0) keycount-; g

7、etpskeycount=0; dispbufkeycount+1=16; else keyoverflag=1; else if(key=15)/enter key if(keycount!=pslen) errorflag=1; rightflag=0; second3=0; else for(i=0;i0;i-) for(j=248;j0;j-); temp=P3; temp=temp if (temp!=0x0f) temp=P3; temp=temp switch(temp) case 0x0e: key=1; break; case 0x0d: key=2; break; case

8、 0x0b: key=3; break; case 0x07: key=12; break; temp=P3; / P1_1=P1_1; if(key=0) keyoverflag=1;/key overflow else if(key=12)/delete key if(keycount0) keycount-; getpskeycount=0; dispbufkeycount+1=16; else keyoverflag=1; else if(key=15)/enter key if(keycount!=pslen) errorflag=1; rightflag=0; second3=0;

9、 else for(i=0;i0;i-) for(j=248;j0;j-); temp=P3; temp=temp if (temp!=0x0f) temp=P3; temp=temp switch(temp) case 0x0e: key=0; break; case 0x0d: key=13; break; case 0x0b: key=14; break; case 0x07: key=15; break; temp=P3; / P1_1=P1_1; if(key=0) keyoverflag=1;/key overflow else if(key=12)/delete key if(k

10、eycount0) keycount-; getpskeycount=0; dispbufkeycount+1=16; else keyoverflag=1; else if(key=15)/enter key if(keycount!=pslen) errorflag=1; rightflag=0; second3=0; else for(i=0;ikeycount;i+) if(getpsi!=psi) i=keycount; errorflag=1; rightflag=0; second3=0; goto a2; errorflag=0; rightflag=1; a2: i=keyc

11、ount; temp=temp while(temp!=0x0f) temp=P3; temp=temp keyoverflag=0; void t0(void) interrupt 1 using 0 TH0=(65536-500)/256; TL0=(65536-500)%256; flashcount+; if(flashcount=8) flashcount=0; P0=dispcodedispbufdispcount; P2=dispbitdispcount; dispcount+; if(dispcount=8) dispcount=0; if(errorflag=1) if(bb

12、=800) bb=0; alarmflag=alarmflag; if(alarmflag=1)/sound alarm signal P1_7=P1_7; aa+; if(aa=800)/light alarm signal aa=0; P1_0=P1_0; second3+; if(second3=6400) second3=0; errorflag=0; rightflag=0; alarmflag=0; bb=0; aa=0; else if(errorflag=0) cc+; if(cc1000) okflag=1; else if(cc2000) okflag=0; else errorflag=0; rightflag=0; P1_7=1; cc=0; oka=0; okb=0; okflag=0; P1_0=1; if(okflag=1) oka+; if(oka=2) oka=0; P1_7=P1_7; else okb+; if(okb=3) okb=0; P1_7=P1_7; if(keyoverflag=1) P1_7=P1_7;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号