采用EDA技术和VHDL语言设计电子密码锁.doc

上传人:laozhun 文档编号:4150766 上传时间:2023-04-07 格式:DOC 页数:32 大小:760.50KB
返回 下载 相关 举报
采用EDA技术和VHDL语言设计电子密码锁.doc_第1页
第1页 / 共32页
采用EDA技术和VHDL语言设计电子密码锁.doc_第2页
第2页 / 共32页
采用EDA技术和VHDL语言设计电子密码锁.doc_第3页
第3页 / 共32页
采用EDA技术和VHDL语言设计电子密码锁.doc_第4页
第4页 / 共32页
采用EDA技术和VHDL语言设计电子密码锁.doc_第5页
第5页 / 共32页
点击查看更多>>
资源描述

《采用EDA技术和VHDL语言设计电子密码锁.doc》由会员分享,可在线阅读,更多相关《采用EDA技术和VHDL语言设计电子密码锁.doc(32页珍藏版)》请在三一办公上搜索。

1、一、设计思想本设计采用EDA技术和VHDL语言设计了一种按键输入密码并数码管回显,当输入正确密码时轰动绿灯亮、红灯熄灭表示开锁,而当输入错误密码时,红灯亮、绿灯熄灭表示关锁。根据系统设计要求,系统设计采用自顶向下的设计方法。1.基本原理在本实验中采用的是VHDL编程,通过文本编辑方式建立模块,通过原理图方式将生成的图形符号连接,然后再下载,进行硬件的仿真。密码锁要达到的功能为:为达到密码锁的以上功能,可将电子密码锁分为以下几个模块:密码锁输入电路、密码锁控制电路、LED输出显示电路。、密码输入:每按下一个数字键,就输入一个数值,并在显示器上显示出该数值。同时将先前输入的数据依次左移一个数字位置

2、。程序下载后系统进入原始状态(原始密码000000),按下键8发光二极管8(绿灯)亮、法官二极管7(红灯)灭。当要重新设置密码时,直接输入自己想要设置的密码并按下键8,持续5S,数码管8由0变为1,此时7段数码管1、2、3、4、5、6对应显示新设置的密码。当要输入密码时,按下键7,先将密码清零,再随机输入一组6位密码,假如密码正确,发光二极管8(绿灯)立即亮;反之如不正确,等待5S,发光二极管7(红灯)亮并由蜂鸣器发出20S的报警信号。、密码清除:按下清除键可清除前面所有的输入值,清除成为“0000”。、密码更改:按下更改键可将目前数据设定为新的密码。、密码上锁:按下上锁键可将密码锁上锁。、密

3、码解除:按下解除键首先检查输入的密码是否正确,密码正确即解锁。2.设计框图为达到密码锁的以上功能,可将电子密码锁分为以下几个模块:密码锁输入电路、密码锁控制电路、LED输出显示电路。和报警电路等四部分组成顶层设计采用原理图设计方式,系统的整体组装设计原理图如图1所示。密码模块校对模块5S延时脉冲模块红灯灭绿灯亮绿灯灭红灯亮20S报警20延时脉冲模块关锁开锁图1 系统整体组装设计原理图二、设计步骤和调试过程1、模块设计和相应模块代码(1)分频由于要产生5秒、20秒的计时信号,故对系统时钟clk_1k进行分频来得到1Hz的时钟clk。其模块及部分程序如下:图2 分频模块process(clk_1k

4、)variable count:std_logic_vector(9 downto 0);beginif(clk_1kevent and clk_1k=1) thencount:=count+1;end if;clk=count(9);end process;仿真波形如下:图3 分频仿真图(2) 设置密码本模块主要是将设置的密码锁存到中间变量ram中去,同时控制灯的变化,由于这里的灯并不能作为最终的输出,所以这里先用led_r_temp1、led_r_temp2代替。其模块及部分程序如下:图4 设置密码模块process(enter1,set)beginif(enter1event and e

5、nter1=1) thenif(set=0) thenram=datain;led_r_temp1=1;led_g_temp1=0;else led_r_temp1=0;led_g_temp1=0;end if;end if;end process;仿真波形如下: 图5 设置密码仿真图(3) 输入密码时第一个按键判断信号本模块主要在密码输入下,当第一个按键按下时产生一个judge信号(高电平有效),其模块及部分程序如下:图6 判断信号模块process(set,clk_1k,datain)beginif(clk_1kevent and clk_1k=1) thenif(set=0) then

6、judge=0;elsif(set=1) thenif(datain(0) or datain(1) or datain(2) or datain(3)=0) then judge=0;els if(datain(0) or datain(1) or datain(2) or datain(3)=1) thenjudge=1;else judge=0;end if;end if;end if;end process;仿真波形如下: 图7 判断信号仿真图从仿真波形上看,当按键按下后judge信号由0变为1,但是当按键重新弹回0时,judge信号又回到0,所以需对judge高电平信号进行锁存: 图

7、8 锁存模块signal temp:std_logic:=0;beginprocess(judge)begin if(judgeevent and judge=1) thentemp=1;end if;end process;judge_load=temp;仿真波形如下:图9 锁存模块仿真图(4) 5秒计时信号该模块是产生一个5秒计时的信号state,5秒期间为1,当5秒时间过去后state变为0,并作为报警信号。其模块及部分程序如下:图10 5秒计时信号模块signal count_5:std_logic_vector(2 downto 0);signal state1:std_logic;

8、beginprocess(clk)beginif(clkevent and clk=1) then if(judge_load=1) then 第一个按键按下if(count_5=101) thencount_5=101;else count_5state1state1state1state1state1state1=0;end case;end process;state=state1 and set;确保在set置为1而第一个按键没有按下时,state为高电平,即刚进入输入密码状态而第一个按键没有按下时state为高电平。仿真波形如下:图11 5秒计时模块仿真图根据仿真波形可以看出,set

9、为0时设置密码,当set为1时,在judge_load(按键识别信号)为0的情况下,state为1,保证下面将要提及的报警模块不会工作,而只有当judge_load为1,且5秒过后state变为0时才有可能发出报警信号(密码输错的情况下)。(5) 开锁信号的产生本模块主要是对输入的密码进行判断,一旦密码输入正确,产生一个开锁信号unlock(高电平有效)。其模块与部分程序如下: 图12 开锁信号模块process(enter2)begin if(enter2event and enter2=1) then输入密码确认if(set=1) then if(state=1) then5秒期间if(d

10、atain=ram) thenunlock=1;开锁信号else unlock=0;end if;end if;end if;end if;end process;输入正确密码仿真波形:图13 开锁信号仿真图输入错误密码仿真波形: 图14 开锁信号仿真图(6) 报警模块本模块主要是在5秒限制时间结束时,如果还没有开锁,就产生报警信号。即长达20秒的声光信号。这里的报警信号指示灯用led_r_temp3表示,扬声器用speaker_temp2表示。其模块及部分程序如下: 图15 报警模块signal count_20:std_logic_vector(4 downto 0);signal tem

11、p:std_logic; beginprocess(clk)beginif(clkevent and clk=1) thenif(set=0)thentemp=0;elsif(set=1) thenif(state=0) thenif(count_20=10100) then count_20=10100;temp=0;else count_20=count_20+1;temp=1;speaker_temp2=clk_1k;end if;end if;end if;end if;end process;led_r_temp3=temp and clk and (not unlock);spea

12、ker_temp2=temp and clk_1k and (not unlock);仿真波形如下:图16 报警模块仿真图可见当state由1变为0且没有unlock信号时,输出20秒的声光信号以示报警。(7) 开锁信号控制指示灯变化模块本模块是实现当开锁信号产生时,相应的指示灯由红亮绿灭变成红灭绿亮。这里同样先用led_r_temp2、led_g_temp2代表红灯和绿灯。其模块及部分程序如下: 图17 指示灯变化模块process(clk_1k,state)beginif(clk_1kevent and clk_1k=1) then if(state=1) then if(unlock=1

13、) thenled_r_temp2=0;led_g_temp2=1;else led_r_temp2=1;led_g_temp2=0;end if;end if;end if;end process;仿真波形如下:图18 指示灯变化仿真图(8) 开锁信号产生2秒提示音模块当开锁信号产生时,扬声器发出两秒的提示音。这里用speaker_temp2代替。其模块及部分程序如下: 图19 2秒提示音模块signal count_2:std_logic_vector(1 downto 0);signal temp:std_logic;beginprocess(clk)beginif(clkevent a

14、nd clk=1) then1秒Hzif(unlock=1) then if(count_2=10) thencount_2=10;temp=0;else count_2=count_2+1;temp=1;end if;end if;end if;end process;speaker_temp1=clk_1k and temp;仿真波形如下:图20 2秒提示音仿真图(9) 指示灯综合输出模块本模块主要是将led_r_temp1、led_g_temp1、led_r_temp2、led_g_temp2经过条件判断选择输出,设置密码(set=0)时输出led_r_temp1、led_g_temp1

15、,输入密码(set=1)时输出led_r_temp2、led_g_temp2。其模块及部分程序如下: 图21 指示灯综合输出模块if(set=0) then led_r=led_r_temp1; led_g=led_g_temp1;elseled_r=led_r_temp2;led_g=led_g_temp2;仿真波形如下: 图22 指示灯综合输出仿真图(10)扬声器综合输出模块本模块主要是将报警音speaker_temp1和开锁提示音speaker_temp2经过条件选择判断输出,set=0时,输出为0;当set=1且unlock=0时输出speaker_temp1,当unlock=1时,输

16、出speaker_temp2。其模块及部分程序如下: 图23 扬声器综合输出模块if(set=0) thenspeaker=0;elsif(unlock=1) then speaker=speaker_temp1;elsespeaker=speaker_temp2;end if;仿真波形如下:图24 扬声器综合输出仿真图2、仿真及仿真结果分析将程序下载Cyclone系列芯片中,同时在EDA试验箱上进行硬件验证。本文提出的电子密码锁由于采用VHDL语言设计,用一片FPGA实现,因而体积小,功耗低,稍加修改就可以改变密码的位数和输入密码的次数,具有较好的应用前景。但由于结构还比较简单,有待进一步完

17、善。输入错误密码:图25 输入错误密码仿真图输入正确密码:图26 输入正确密码仿真图3、实验调试结果密码锁的控制电路是整个电路的控制中心,主要完成对数字按键输入和功能按键输入的响应控制。、数字按键输入的响应控制如果按下数字键,第一个数字会从显示器的最右端开始显示,此后每新按下一个数字时,显示器上的数字必须左移一位,一边将新的数字显示出来。假如要更改输入的数字,可以按倒退按键来清除前一个输入的数字,或者按清除键清除所有输入的数字,再重新输入四位数。由于这里设计的是一个四位的电子密码锁,所以当输入的数字键超过四个时,电路不予理会,而且不再显示第四个以后的数字。、功能按键输入响应控制清除键:清除所有

18、的输入数字,即做归零动作。上锁键:按下此键时可将密码锁的门上锁(上锁前必须先设定一个四位的电子密码)。电子密码锁的整合和验证。三、结论及心得体会本课程设计主要是基于VHDL文本输入法设计电子密码锁,随着社会物质财富的日益增长,安全防盗已成为全社会关注的问题。基于EDA技术设计的电子密码锁,以其价格便宜、安全可靠、使用方便,受到了人们的普遍关注。而以现场可编程逻辑器件(FPGA)为设计载体,以硬件描述语言(VHDE)为主要表达方式,以Quartus开发软件和GW48EDA开发系统为设计工具设计的电子密码锁,由于其能够实现数码输入、数码清除、密码解除、密码更改、密码上锁和密码解除等功能,因此,能够

19、满足社会对安全防盗的要求。通过本次课程设计我收获颇多,刚开始拿到题目后,没有一个明确的方案,查了很多资料,大部分都用到了矩阵键盘,并且比较复杂,后来根据实验箱设计了该方案。这就要求我们要根据现实的条件去设计适合自己硬件的程序。在这次课程设计中,最头疼的问题就是各个模块仿真正确后,最后的顶层文件却并没有达到预期的效果,很是令人灰心,并无从查找。后来我试着把每一个模块逐渐添加到顶层中,每添加一个就仿真一下,并留意中间信号量的变化,根据波形去调试相应的模块,最终得到了想要的波形。当然期间遇到了很多的困难,通过向老师同学请教,并积极思考,最终这些难题都得到了解决,这也让我懂得了团队的重要性。参考资料:

20、1 潘松著.EDA技术实用教程(第二版). 北京:科学出版社,2005.2 康华光主编.电子技术基础 模拟部分. 北京:高教出版社,2006.3 阎石主编.数字电子技术基础. 北京:高教出版社,2003.4 谭会生、瞿遂春.EDA技术综合应用实例与分析.西安电子科技大学出版社,20045 高有堂.EDA技术及应用实践.清华大学出版社,20066候伯亨著.VHDL硬件描述语言与数字逻辑电路设计M.西安:西安电子科技大学出版社,2009.7张昌凡著.可编程逻辑器件及VHDL设计技术M.广州:华南理工大学出版社,2001. 8曹昕燕、周凤臣等.EDA技术实验与课程设计.清华大学出版社,2006源程序

21、:【1】 library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fenpin isport(clk_1k:in std_logic; clk:out std_logic);end;architecture rtl of fenpin isbeginprocess(clk_1k)variable count:std_logic_vector(9 downto 0);beginif(clk_1kevent and clk_1k=1) thencount:=count+1;end if;clk=

22、count(9);end process;end rtl;【2】library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity code_set isport(set,enter1:in std_logic;datain:in std_logic_vector(3 downto 0);ram:out std_logic_vector(3 downto 0);led_r_temp1,led_g_temp1:out std_logic);end;architecture rtl of code_set

23、isbeginprocess(enter1,set)beginif(enter1event and enter1=1) thenif(set=0) then ram=datain;led_r_temp1=1;led_g_temp1=0;else led_r_temp1=0;led_g_temp1=0;end if;end if;end process;end;【3】library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity judge isport(clk_1k,set:in std_logic

24、;datain:in std_logic_vector(3 downto 0);judge:out std_logic);end;architecture rtl of judge isbeginprocess(set,clk_1k,datain)beginif(clk_1kevent and clk_1k=1) thenif(set=0) then judge=0;elsif(set=1) thenif(datain(0) or datain(1) or datain(2) or datain(3)=0) then judge=0;elsif(datain(0) or datain(1) o

25、r datain(2) or datain(3)=1) thenjudge=1;else judge=0;end if;end if;end if;end process;end;【4】library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity judge_load isport(judge:in std_logic;judge_load:out std_logic);end;architecture rtl of judge_load issignal temp:std_logic:=0;be

26、ginprocess(judge)beginif(judgeevent and judge=1) thentemp=1;end if;end process;judge_load=temp;end;【5】library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity time_5 isport(clk,judge_load,set:in std_logic;state:out std_logic);end;architecture rtl of time_5 issignal count_5:std

27、_logic_vector(2 downto 0);signal state1:std_logic;beginprocess(clk)beginif(clkevent and clk=1) thenif(judge_load=1) then if(count_5=101) thencount_5=101;else count_5state1state1state1state1state1state1=0;end case;end process;state=state1 and set;end;【6】library ieee;use ieee.std_logic_1164.all;use ie

28、ee.std_logic_unsigned.all;entity unlock isport(set,enter2,state:in std_logic;datain,ram:in std_logic_vector(3 downto 0);unlock:out std_logic);end;architecture rtl of unlock isbeginprocess(enter2)beginif(enter2event and enter2=1) thenif(set=1) then if(state=1) thenif(datain=ram) thenunlock=1;else unl

29、ock=0;end if;end if;end if;end if;end process;end rtl;【7】library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity unlock_led isport(state,unlock,clk_1k:in std_logic;led_r_temp2,led_g_temp2:out std_logic);end;architecture rtl of unlock_led isbeginprocess(clk_1k,state)beginif(cl

30、k_1kevent and clk_1k=1) thenif(state=1) then if(unlock=1) thenled_r_temp2=0;led_g_temp2=1;else led_r_temp2=1;led_g_temp2=0;end if;end if;end if;end process;end;【8】library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity unlock_sound isport(clk,unlock,clk_1k:in std_logic;speake

31、r_temp1:out std_logic);end;architecture rtl of unlock_sound issignal count_2:std_logic_vector(1 downto 0);signal temp:std_logic;beginprocess(clk)beginif(clkevent and clk=1) thenif(unlock=1) then if(count_2=10) thencount_2=10;temp=0;else count_2=count_2+1;temp=1;end if;end if;end if;end process;speak

32、er_temp1=clk_1k and temp;end;【9】library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity alert isport(state,clk,clk_1k,set,unlock:in std_logic;led_r_temp3,speaker_temp2:out std_logic);end;architecture rtl of alert issignal count_20:std_logic_vector(4 downto 0);signal temp:std_

33、logic;beginprocess(clk)beginif(clkevent and clk=1) thenif(set=0)thentemp=0;elsif(set=1) thenif(state=0) thenif(count_20=10100) then count_20=10100;temp=0;else count_20=count_20+1;temp=1;end if;end if;end if;end if;end process;led_r_temp3=temp and clk and (not unlock);speaker_temp2=temp and clk_1k an

34、d (not unlock);end;【10】library ieee;use ieee.std_logic_1164.all;entity led isport(led_r_temp1,led_r_temp2,led_g_temp1,led_g_temp2,set:in std_logic;led_r,led_g:out std_logic);end;architecture rtl of led is beginprocess(set)beginif(set=0) then led_r=led_r_temp1;led_g=led_g_temp1;elseled_r=led_r_temp2;

35、led_g=led_g_temp2;end if;end process;end;【11】library ieee;use ieee.std_logic_1164.all;entity speaker isport(unlock,speaker_temp1,speaker_temp2,set:in std_logic;speaker:out std_logic);end;architecture rtl of speaker isbeginprocess(unlock)beginif(set=0) thenspeaker=0;elsif(unlock=1) thenspeaker=speaker_temp1;elsespeaker=speaker_temp2;end if;end process;end;

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

当前位置:首页 > 办公文档 > 其他范文


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号