EDA电子密码锁1.docx

上传人:b****2 文档编号:3231904 上传时间:2023-05-05 格式:DOCX 页数:24 大小:302.02KB
下载 相关 举报
EDA电子密码锁1.docx_第1页
第1页 / 共24页
EDA电子密码锁1.docx_第2页
第2页 / 共24页
EDA电子密码锁1.docx_第3页
第3页 / 共24页
EDA电子密码锁1.docx_第4页
第4页 / 共24页
EDA电子密码锁1.docx_第5页
第5页 / 共24页
EDA电子密码锁1.docx_第6页
第6页 / 共24页
EDA电子密码锁1.docx_第7页
第7页 / 共24页
EDA电子密码锁1.docx_第8页
第8页 / 共24页
EDA电子密码锁1.docx_第9页
第9页 / 共24页
EDA电子密码锁1.docx_第10页
第10页 / 共24页
EDA电子密码锁1.docx_第11页
第11页 / 共24页
EDA电子密码锁1.docx_第12页
第12页 / 共24页
EDA电子密码锁1.docx_第13页
第13页 / 共24页
EDA电子密码锁1.docx_第14页
第14页 / 共24页
EDA电子密码锁1.docx_第15页
第15页 / 共24页
EDA电子密码锁1.docx_第16页
第16页 / 共24页
EDA电子密码锁1.docx_第17页
第17页 / 共24页
EDA电子密码锁1.docx_第18页
第18页 / 共24页
EDA电子密码锁1.docx_第19页
第19页 / 共24页
EDA电子密码锁1.docx_第20页
第20页 / 共24页
亲,该文档总共24页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

EDA电子密码锁1.docx

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

EDA电子密码锁1.docx

EDA电子密码锁1

电子密码锁

设计要求

1)设计一个密码锁的控制电路,当输入正确代码时,输出开锁信号以推动执行机构工作,用红灯亮、绿灯熄灭表示关锁,用绿灯亮、红灯熄灭表示开锁;

2)在锁的控制电路中储存一个可以修改的4位代码,当开锁按钮开关(可设置成6位至8位,其中实际有效为4位,其余为虚设)的输入代码等于储存代码时,开锁;

3)从第一个按钮触动后的5秒内若未将锁打开,则电路自动复位并进入自锁状态,使之无法再打开,并由扬声器发出持续20秒的报警信号。

1.方案论证与对比

1.1方案一

方案一是用以AT89C2051为核心的单片机控制方案。

共设了9个用户输入键,其中只有4个是有效的密码按键,其它的都是干扰按键,若按下干扰键,键盘输入电路自动清零,原先输入的密码无效,需要重新输入;如果用户输入密码的时间超过40秒(一般情况下,用户不会超过40秒,若用户觉得不便,还可以修改)电路将报警80秒,若电路连续报警三次,电路将锁定键盘5分钟,防止他人的非法操作。

设计方框图如图1所示。

1.2方案二

方案二是用本学期所学的EDA技术中的VHDL语言来实现方案。

设计方框图如图2所示。

1.3比较

由于单片机方案原理复杂,而且调试较为繁琐,并且是用C语言或者汇编语言实现功能,构成的是软件,容易受到外界影响;而有EDA技术中VHDL(硬件描述语言),构成的是硬件本身,不容易受到外界的干扰,所以本文采用后一种方案。

方案一是基于软件的编程语言,对硬件和软件的要求都很高,方案二则是基于硬件设计的语言,很容易对硬件电路实现编程下载;

2.总体模块设计

本设计采用EDA技术和VHDL语言设计了一种按键输入密码并数码管回显,当输入正确密码时轰动绿灯亮、红灯熄灭表示开锁,而当输入错误密码时,红灯亮、绿灯熄灭表示关锁。

根据系统设计要求,系统设计采用自顶向下的设计方法。

顶层设计采用原理图设计方式,系统的整体组装设计原理图如图2-1所示。

它由时钟电路按键控制输入模块、密码锁控制模块、数码管与LED显示模块和报警电路等四部分组成。

程序下载后系统进入原始状态(原始密码000000),按下键8发光二极管8(绿灯)亮、法官二极管7(红灯)灭。

当要重新设置密码时,直接输入自己想要设置的密码并按下键8,持续5S,数码管8由0变为1,此时7段数码管1、2、3、4、5、6对应显示新设置的密码。

当要输入密码时,按下键7,先将密码清零,再随机输入一组6位密码,假如密码正确,发光二极管8(绿灯)立即亮;反之如不正确,等待5S,发光二极管7(红灯)亮并由蜂鸣器发出20S的报警信号。

3.单元模块设计

3.1顶层模块设计

该电子密码锁顶层文件使用原理图输入法,将按键、延时、判断正误、出错红灯亮并报警、正确绿灯亮这几个模块连接在一起实现6位二进制密码锁功能。

具体顶层原理图如图3所示:

图3密码锁顶层文件原理图

3.2密码输入模块

1、本按键输入模块包括设置密码并读取、密码清零、输入密码、系统复位功能。

该模块中我们设置了8个按键,各个按键的功能分别为:

按键1、2、3、4、5、6分别对应6位二进制密码输入、键7为密码清零按键、键8为系统复位和密码读取按键。

2、以上各子模块的设计均采用VHDL语言实现,其具体实现程序如下:

LibraryIEEE;

useIEEE.std_logic_1164.all;

useIEEE.std_logic_unsigned.all;

entitykeyis

port(key_in1,key_in2,key_in3,key_in4,key_in5,key_in6:

instd_logic;

clk:

instd_logic;

str:

instd_logic;

resert:

instd_logic;

clk20:

instd_logic;

ds:

instd_logic;

key_out:

outstd_logic_vector(5downto0);

key_read:

outstd_logic;

key_resert:

outstd_logic;

key_r:

outstd_logic);

endkey;

architecturekey_mimaofkeyis

signalm:

std_logic_vector(5downto0);

signalsa:

std_logic_vector(5downto0);

signaldd:

std_logic:

='0';

signaldd1:

std_logic;

signalcount:

std_logic_vector(3downto0);

signalcount2:

std_logic_vector(3downto0);

signalcount3:

std_logic_vector(3downto0);

begin

c0:

process(resert,key_in1,key_in2,key_in3,key_in4,key_in5,key_in6)

begin

ifresert='1'thendd<='0';--全部清零

elseifkey_in1='1'orkey_in2='1'orkey_in3='1'orkey_in4='1'orkey_in5='1'orkey_in6='1'

thendd<='1';endif;endif;--只要有键按下,dd将为高电平不变

key_r<=dd;

endprocessc0;

cc:

process(key_in5,key_in6,clk,resert)

begin

ifclk'eventandclk='1'then

ifds='1'

then--保持ds='1',持续5秒高电平5秒后产生低电平,第5秒为低电平

--按下键八5秒后读取密码

ifcount<6then

key_read<='0';count<=count+1;elsecount<=count;

endif;

ifcount=5thenkey_read<='1';endif;

elsecount<="0000";key_read<='0';

endif;

endif;

endprocesscc;

cc2:

process(key_in1,key_in2,clk,resert)

begin

ifclk'eventandclk='1'then

ifds='1'

then--保持ds='1',持续3秒高电平3秒后产生低电平,第3秒为低电平

--按下按下键八三秒后对错误复位

ifcount2<4then

key_resert<='0';count2<=count2+1;elsecount2<=count2;

endif;

ifcount2=3thenkey_resert<='1';endif;

elsecount2<="0000";key_resert<='0';

endif;

endif;

endprocesscc2;

c1:

process(key_in1,str,sa)--按键1输入

begin

ifstr='1'orsa(0)='1'thenm(0)<='0';else

ifkey_in1'eventandkey_in1='1'thenm(0)<=notm(0);endif;

endif;

endprocessc1;

c2:

process(key_in2,str,sa)--按键2输入

begin

ifstr='1'orsa

(1)='1'thenm

(1)<='0';else

ifkey_in2'eventandkey_in2='1'thenm

(1)<=notm

(1);endif;

endif;

endprocessc2;

c3:

process(key_in3,str,sa)--按键3输入

begin

ifstr='1'orsa

(2)='1'thenm

(2)<='0';else

ifkey_in3'eventandkey_in3='1'thenm

(2)<=notm

(2);endif;

endif;

endprocessc3;

c4:

process(key_in4,str,sa)--按键4输入

begin

ifstr='1'orsa(3)='1'thenm(3)<='0';else

ifkey_in4'eventandkey_in4='1'thenm(3)<=notm(3);endif;

endif;

endprocessc4;

c5:

process(key_in5,str,sa)--按键5输入

begin

ifstr='1'orsa(4)='1'thenm(4)<='0';else

ifkey_in5'eventandkey_in5='1'thenm(4)<=notm(4);endif;

endif;

endprocessc5;

c6:

process(key_in6,str,sa)--按键6输入

begin

ifstr='1'orsa(5)='1'thenm(5)<='0';else

ifkey_in6'eventandkey_in6='1'thenm(5)<=notm(5);endif;

endif;

endprocessc6;

v22:

process(resert,clk20)

begin

ifclk20'eventandclk20='1'then

ifresert='1'then

ifcount3=7thencount3<=count3;else

count3<=count3+1;sa<="000000";

ifcount3=5thensa<="111111";elsesa<="000000";endif;

endif;

elsecount3<="0000";

endif;endif;

endprocessv22;

key_out<=mand(notsa);

endkey_mima;

图4密码输入模块

密码输入模块仿真如下(图5):

3.3显示模块

1、本设计要求输入正确密码时,绿灯亮、红灯熄灭;当输入错误密码时,5S后红灯亮绿灯灭,同时要求发出20S的报警。

为此我们设计发光二极管D7和D8分别表示红灯和绿灯,并用蜂鸣器作为报警电路。

2、LED显示电路的VHDL程序如下:

LibraryIEEE;

useIEEE.std_logic_1164.all;

useIEEE.std_logic_unsigned.all;

entityledis

port(r:

instd_logic;

str:

instd_logic;

str5:

instd_logic;

ar:

outstd_logic);

endled;

architectureled_mimaofledis

signals1:

std_logic:

='0';

begin

b1:

process(str,r,str5)

begin

ifstr='0'then

ifr'eventandr='1'thenifstr5='1'thens1<='1';endif;endif;

elses1<='0';

endif;

endprocessb1;

ar<=s1;

endled_mima;

图6LED显示模块

LED显示模块仿真如下(图7):

3、报警电路程序设计如下:

LibraryIEEE;

useIEEE.std_logic_1164.all;

useIEEE.std_logic_unsigned.all;

entitysoundis

port(str:

instd_logic;

clk:

instd_logic;

sound_out:

outstd_logic);

endsound;

architecturexd_soundofsoundis

signalss:

std_logic;

begin

process(str,clk)--产生20报警电路,需要str为高电平20秒

begin

ifstr='1'then

ss<=clk;

elsess<='0';

endif;

sound_out<=ss;

endprocess;

endxd_sound;

图8报警模块

报警模块仿真如下(图9):

3.4延时模块

1、针对本设计中要求的输入错误密码后5S报错和20S报警,我们设计了5S和20S的两个延时模块。

2、延时5S程序设计:

LibraryIEEE;

useIEEE.std_logic_1164.all;

useIEEE.std_logic_unsigned.all;

entitymcis

port(str:

instd_logic;

clk:

instd_logic;

key_out:

outstd_logic);

endmc;

architecturemc_mimaofmcis

signalcount:

std_logic_vector(3downto0);

begin

process(str,clk)

begin

ifclk'eventandclk='1'then

ifstr='1'then--保持str为1,5秒高电平5秒后产生低电平,第6秒为低电平

ifcount<6thenkey_out<='1';

count<=count+1;elsecount<=count;

endif;

ifcount=5thenkey_out<='0';endif;

elsecount<="0000";key_out<='0';

endif;

endif;

endprocess;

endmc_mima;

图10延时5秒模块

延时5秒模块仿真如下(图11):

3、延时20S程序如下:

LibraryIEEE;

useIEEE.std_logic_1164.all;

useIEEE.std_logic_unsigned.all;

entitym20is

port(str:

instd_logic;

clk:

instd_logic;

key_out:

outstd_logic);

endm20;

architecturem20_mimaofm20is

signalcount:

std_logic_vector(4downto0);

begin

process(str,clk)

begin

ifclk'eventandclk='1'then

ifstr='1'then--保持str为1,20秒高电平20秒后产生低电平,第21秒为低电平

ifcount<21thenkey_out<='1';

count<=count+1;elsecount<=count;

endif;

ifcount=20thenkey_out<='0';endif;

elsecount<="00000";key_out<='0';

endif;

endif;

endprocess;

endm20_mima;

图12延时20秒模块

延时20秒模块仿真如下(图13):

3.5设置密码以及验证模块

1、中要求密码可以设置,为了更清晰的了解密码,我们除了设计密码设置键外,还设置了数码管显示设置好的密码。

该模块采用VHDL语言设计而成。

2、设置密码输入程序如下:

LibraryIEEE;

useIEEE.std_logic_1164.all;

useIEEE.std_logic_unsigned.all;

entityledwis

port(ee:

instd_logic;

str:

instd_logic;

str5:

instd_logic;

aw:

outstd_logic);

endledw;

architectureledw_mimaofledwis

signals1:

std_logic:

='0';

begin

process(str,ee,str5)

begin

ifstr='0'then

ifstr5'eventandstr5='0'then

ifee='0'then

s1<='1';

endif;

endif;

elses1<='0';endif;

endprocess;

aw<=s1;

endledw_mima;

图14密码及验证模块

密码及验证模块仿真如下(图15):

3、密码电路程序如下:

LIBRARYieee;

USEIEEE.STD_LOGIC_1164.ALL;

useIEEE.std_logic_unsigned.all;

entitymimais

PORT(clk_mima:

INSTD_LOGIC;

key:

INSTD_LOGIC_VECTOR(5downto0);

mima_out:

OUTSTD_LOGIC_VECTOR(5downto0));

endmima;

ARCHITECTUREoneOFmimaIS

signals:

std_logic_vector(5downto0);

begin

process(clk_mima,key)

begin

ifclk_mima='1'then

s<=key;

elsenull;

endif;

mima_out<=s;

endprocess;

endone;

4、密码校对电路程序设计如下:

LibraryIEEE;

useIEEE.std_logic_1164.all;

useIEEE.std_logic_unsigned.all;

entityxdis--密码校对

port(str:

instd_logic;

a:

instd_logic_vector(5downto0);

b:

instd_logic_vector(5downto0);

key_out:

outstd_logic);

endxd;

architecturexd_mimaofxdis

signalss:

std_logic:

='0';

begin

process(a(0),a

(1),a

(2),a(3),a(4),a(5),str)

begin

ifstr='1'then

ifa=bthen

ss<='1';

elsess<='0';endif;

elsess<='0';endif;

key_out<=ss;

endprocess;

endxd_mima;

图16密码校对模块

密码校对模块的仿真如下(图17):

4.系统仿真

将程序下载Cyclone系列芯片中,同时在EDA试验箱上进行硬件验证。

本文提出的电子密码锁由于采用VHDL语言设计,用一片FPGA实现,因而体积小,功耗低,稍加修改就可以改变密码的位数和输入密码的次数,具有较好的应用前景。

但由于结构还比较简单,有待进一步完善。

电子密码锁整个系统的仿真如图18

图18电子密码锁整个电路系统仿真图

5.结束语

通过两星期的紧张工作,最后完成了我的设计任务——基于VHDL语言的智能密码锁设计。

通过本次课程设计的学习,我深深的体会到设计课的重要性和目的性所在。

本次设计课不仅仅培养了我们实际操作能力,也培养了我们灵活运用课本知识,理论联系实际,独立自主的进行设计的能力。

它不仅仅是一个学习新知识新方法的好机会,同时也是对我所学知识的一次综合的检验和复习,使我明白了自己的缺陷所在,从而查漏补缺。

希望学校以后多安排一些类似的实践环节。

附录

主控制程序参考如下:

LIBRARYieee;

USEieee.std_logic_1164.all;

USEieee.std_logic_unsigned.all;

LIBRARYwork;

ENTITYlockIS

port(str:

INSTD_LOGIC;

clk20:

INSTD_LOGIC;

clk1:

INSTD_LOGIC;

ds:

INSTD_LOGIC;

key_1:

INSTD_LOGIC_VECTOR(5downto0);

green:

OUTSTD_LOGIC;

red:

OUTSTD_LOGIC;

sound_1:

OUTSTD_LOGIC;

xianshi:

OUTSTD_LOGIC;

key_read:

OUTSTD_LOGIC;

display:

OUTSTD_LOGIC_VECTOR(5downto0);

key_tell:

OUTSTD_LOGIC_VECTOR(5downto0));

ENDlock;

ARCHITECTUREoneOFlockIS

componentled

PORT(r:

INSTD_LOGIC;

str:

INSTD_LOGIC;

str5:

INSTD_LOGIC;

ar:

OUTSTD_LOGIC);

endcomponent;

componentsound

PORT(str:

INSTD_LOGIC;

clk:

INSTD_LOGIC;

sound_out:

OUTSTD_LOGIC);

endcomponent;

componentmc

PORT(str:

INSTD_LOGIC;

clk:

INSTD_LOGIC;

key_out:

OUTSTD_LOGIC);

endcomponent;

componentxd

PORT(str:

INSTD_LOGIC;

a:

INSTD_LOGIC_VECTOR(5downto0);

b:

INSTD_LOGIC_VECTOR(5downto0);

key_out:

OUTSTD_LOGIC);

endcomponent;

componentmima

PORT(clk_mima:

INSTD_LOGIC;

key

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

当前位置:首页 > 解决方案 > 学习计划

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

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