电子密码锁2.docx

上传人:b****3 文档编号:4739757 上传时间:2023-05-07 格式:DOCX 页数:9 大小:15.71KB
下载 相关 举报
电子密码锁2.docx_第1页
第1页 / 共9页
电子密码锁2.docx_第2页
第2页 / 共9页
电子密码锁2.docx_第3页
第3页 / 共9页
电子密码锁2.docx_第4页
第4页 / 共9页
电子密码锁2.docx_第5页
第5页 / 共9页
电子密码锁2.docx_第6页
第6页 / 共9页
电子密码锁2.docx_第7页
第7页 / 共9页
电子密码锁2.docx_第8页
第8页 / 共9页
电子密码锁2.docx_第9页
第9页 / 共9页
亲,该文档总共9页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

电子密码锁2.docx

《电子密码锁2.docx》由会员分享,可在线阅读,更多相关《电子密码锁2.docx(9页珍藏版)》请在冰点文库上搜索。

电子密码锁2.docx

电子密码锁2

电子密码锁2

1.实验任务

根据设定好的密码,采用二个按键实现密码的输入功能,当密码输入正确之后,锁就打开,如果输入的三次的密码不正确,就锁定按键3秒钟,同时发现报警声,直到没有按键按下3种后,才打开按键锁定功能;否则在3秒钟内仍有按键按下,就重新锁定按键3秒时间并报警。

2.电路原理图

图4.32.1

3.系统板上硬件连线

(1).把“单片机系统”区域中的P0.0/AD0用导线连接到“音频放大模块”区域中的SPKIN端子上;

(2).把“音频放大模块”区域中的SPKOUT端子接喇叭和;

(3).把“单片机系统”区域中的P2.0/A8-P2.7/A15用8芯排线连接到“四路静态数码显示”区域中的任一个ABCDEFGH端子上;

(4).把“单片机系统“区域中的P1.0用导线连接到“八路发光二极管模块”区域中的L1端子上;

(5).把“单片机系统”区域中的P3.6/WR、P3.7/RD用导线连接到“独立式键盘”区域中的SP1和SP2端子上;

4.程序设计内容

(1).密码的设定,在此程序中密码是固定在程序存储器ROM中,假设预设的密码为“12345”共5位密码。

(2).密码的输入问题:

由于采用两个按键来完成密码的输入,那么其中一个按键为功能键,另一个按键为数字键。

在输入过程中,首先输入密码的长度,接着根据密码的长度输入密码的位数,直到所有长度的密码都已经输入完毕;或者输入确认功能键之后,才能完成密码的输入过程。

进入密码的判断比较处理状态并给出相应的处理过程。

(3).按键禁止功能:

初始化时,是允许按键输入密码,当有按键按下并开始进入按键识别状态时,按键禁止功能被激活,但启动的状态在3次密码输入不正确的情况下发生的。

5.C语言源程序

#include

unsignedcharcodeps[]={1,2,3,4,5};

unsignedcharcodedispcode[]={0x3f,0x06,0x5b,0x4f,0x66,

0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};

unsignedcharpslen=9;

unsignedchartemplen;

unsignedchardigit;

unsignedcharfuncount;

unsignedchardigitcount;

unsignedcharpsbuf[9];

bitcmpflag;

bithibitflag;

biterrorflag;

bitrightflag;

unsignedintsecond3;

unsignedintaa;

unsignedintbb;

bitalarmflag;

bitexchangeflag;

unsignedintcc;

unsignedintdd;

bitokflag;

unsignedcharoka;

unsignedcharokb;

voidmain(void)

{

unsignedchari,j;

P2=dispcode[digitcount];

TMOD=0x01;

TH0=(65536-500)/256;

TL0=(65536-500)%256;

TR0=1;

ET0=1;

EA=1;

while

(1)

{

if(cmpflag==0)

{

if(P3_6==0)//functionkey

{

for(i=10;i>0;i--)

for(j=248;j>0;j--);

if(P3_6==0)

{

if(hibitflag==0)

{

funcount++;

if(funcount==pslen+2)

{

funcount=0;

cmpflag=1;

}

P1=dispcode[funcount];

}

else

{

second3=0;

}

while(P3_6==0);

}

}

if(P3_7==0)//digitkey

{

for(i=10;i>0;i--)

for(j=248;j>0;j--);

if(P3_7==0)

{

if(hibitflag==0)

{

digitcount++;

if(digitcount==10)

{

digitcount=0;

}

P2=dispcode[digitcount];

if(funcount==1)

{

pslen=digitcount;

templen=pslen;

}

elseif(funcount>1)

{

psbuf[funcount-2]=digitcount;

}

}

else

{

second3=0;

}

while(P3_7==0);

}

}

}

else

{

cmpflag=0;

for(i=0;i

{

if(ps[i]!

=psbuf[i])

{

hibitflag=1;

i=pslen;

errorflag=1;

rightflag=0;

cmpflag=0;

second3=0;

gotoa;

}

}

cc=0;

errorflag=0;

rightflag=1;

hibitflag=0;

a:

cmpflag=0;

}

}

}

voidt0(void)interrupt1using0

{

TH0=(65536-500)/256;

TL0=(65536-500)%256;

if((errorflag==1)&&(rightflag==0))

{

bb++;

if(bb==800)

{

bb=0;

alarmflag=~alarmflag;

}

if(alarmflag==1)

{

P0_0=~P0_0;

}

aa++;

if(aa==800)

{

aa=0;

P0_1=~P0_1;

}

second3++;

if(second3==6400)

{

second3=0;

hibitflag=0;

errorflag=0;

rightflag=0;

cmpflag=0;

P0_1=1;

alarmflag=0;

bb=0;

aa=0;

}

}

if((errorflag==0)&&(rightflag==1))

{

P0_1=0;

cc++;

if(cc<1000)

{

okflag=1;

}

elseif(cc<2000)

{

okflag=0;

}

else

{

errorflag=0;

rightflag=0;

hibitflag=0;

cmpflag=0;

P0_1=1;

cc=0;

oka=0;

okb=0;

okflag=0;

P0_0=1;

}

if(okflag==1)

{

oka++;

if(oka==2)

{

oka=0;

P0_0=~P0_0;

}

}

else

{

okb++;

if(okb==3)

{

okb=0;

P0_0=~P0_0;

}

}

}

}

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2