VHDL四位密码锁课程设计.doc

上传人:laozhun 文档编号:4146815 上传时间:2023-04-07 格式:DOC 页数:10 大小:44.50KB
返回 下载 相关 举报
VHDL四位密码锁课程设计.doc_第1页
第1页 / 共10页
VHDL四位密码锁课程设计.doc_第2页
第2页 / 共10页
VHDL四位密码锁课程设计.doc_第3页
第3页 / 共10页
VHDL四位密码锁课程设计.doc_第4页
第4页 / 共10页
VHDL四位密码锁课程设计.doc_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《VHDL四位密码锁课程设计.doc》由会员分享,可在线阅读,更多相关《VHDL四位密码锁课程设计.doc(10页珍藏版)》请在三一办公上搜索。

1、电子与信息工程学院EDA课程设计报告( 2011 2012 学年 第 一 学期)课程设计题目:四位密码锁1. 掌握VHDL语言的使用,学会用VHDL语言来编程解决实际问题;2. 学会使用EDA开发软件设计小型综合电路,掌握仿真的技巧;3. 学会应用开发系统实现硬件电路,检验电路的功能。内容和要求:用VHDL语言设计一个密码锁,用波形仿真验证其功能后,实现到GW48实验系统。功能描述:用于模仿密码锁的工作过程。完成密码锁的核心控制功能。功能要求:设计一个密码锁,平时处于等待状态。管理员可以设置或更改密码。如果不预置密码,密码缺省为“1234”。用户如果需要开锁,按相应的按键进入输入密码状态,输入

2、4位密码,按下确定键后,若密码正确,锁打开;若密码错误,将提示密码错误,要求重新输入,三次输入都错误,将发出报警信号。报警后,只有管理员作相应的处理才能停止报警。用户输入密码时,若输入错误,在按下确定键之前,可以通过按取消键重新输入。正确开锁后,用户处理完毕后,按下确定键,系统回到等待状态。系统操作过程中,只要密码锁没有打开,如果60秒没有对系统操作,系统回到等待状态。要求密码在输入过程中被依次显示,即先输入的为密码的第一位,总是显示在最左边。用两个发光二极管模拟显示,其中一个显示当前的工作模式,灭表示用户模式,亮表示管理员模式;另外一个指示锁的状态,灭表示锁处于锁定,亮表示锁被开启。注意:用

3、两个按键实现密码输入,Key1选择输入的是第几位密码,KEY2输入密码数字。 功能描述:初始状态:初次使用密码锁时,要先用Reset键初始化。初始状态下,用户密码为“1234”,管理员密码为“0000”。用户开锁:默认情况下,密码锁处于用户使用状态。如果当前为管理员状态,则按下user键回到用户状态。用户开锁时,输入四位数用户密码,可以从out_code6的输出状态确定密码输入状态。如输入错误则按下clear清除前一位输入。输入完毕后按enter,如果密码正确,则开锁,否则重新输入密码。开锁后再次按下enter键则关锁,回到等待状态。三次密码输入错误,警报器alarming为1。要管理员输入管

4、理员密码解除警报。此时哪怕用户再输对密码也没用。管理员解除警报:当用户三次密码输入错误的时候,alarming为1,此时,只要管理员密码输入正确后,按下clear键,alarming为0,报警取消。管理员修改密码:在非警报和为开锁状态下,任何时候按admin键进入管理员状态。按chgcode选择修改密码,先选择修改的是用户密码还是管理员密码。修改用户密码则按user键,修改管理员密码则按admin键。然后分别输入旧密码,新密码,新密码要输入两次。旧密码与所要修改的密码对应。如旧密码输入错误,则无法修改;当验证不成功即两次新密码不相同时,修改密码失败。返回等待状态。成功后也返回等待状态。定时返回

5、:用户在未开锁状态下,60s没有按键输入,则返回等待状态,但不包括alarming状态。只要是alarming,则只有管理输入管理员密码才能解锁并按下clear消除警报。设计思路:设计密码锁时,采用自顶向下的设计方法。将整个系统分成几个子模块:输入输出模块,控制模块,按键设置模块和60s计时器模块。 控制模块是整个程序的主要部分,采用状态循环的办法,以用户每按下一次按键为计量单位,划分状态,以实现各种功能。60s计时器模块是完成60s没有按键则返回等待状态这一功能的主要模块。这个模块的核心思想是一个变量numtime计数。变量numtime的初始值为0,在无报警为开锁的情况下,时钟每秒发出一个

6、上升沿信号,计数一次,如有按键则numtime清零,否则计数到60即“111100”则返回信号back变为1,返回等待状态。按键设置模块是将各种功能按键用高低电平赋值,便于调用。设计内容(原理图以及相关说明、调试过程、结果)library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY E_lock IS PORT( clk,user,admin,clear,enter,chgcode,res,key1,key2:IN STD_LOGIC;

7、num:IN STD_LOGIC_VECTOR(9 DOWNTO 0); openlock:buffer std_logic; alarming,o_ua,o_chgcode,chgcode_ua:OUT STD_LOGIC; out_code4:out std_logic_vector(3downto 0) ); END E_lock;ARCHITECTURE behave OF E_lock ISTYPE STATES IS (ss,sw,s0,s1,s2,s3,s4,s5,s6,s7);SIGNAL state:STATES;SIGNAL one_key,code0,code1,code

8、2,code3:STD_LOGIC_VECTOR(3 DOWNTO 0);SIGNAL user_code,admin_code:STD_LOGIC_VECTOR(15 DOWNTO 0); -用户密码 管理员密码SIGNAL temp_code,old_code:STD_LOGIC_VECTOR(15 DOWNTO 0); -当前密码 旧密码SIGNAL new_ctime:STD_LOGIC_VECTOR(1 DOWNTO 0);SIGNAL key:std_logic_vector(7 downto 0);SIGNAL alarm,inkey,ifnum,s_ua,chg_c,c_ua,

9、back:std_logic;SIGNAL out_code:std_logic_vector(3 downto 0);SIGNAL numtime:std_logic_vector(9 downto 0);BEGIN temp_code=code0&code1&code2&code3; key=user&admin&chgcode&enter&clear&res&key1&key2; inkey=user or admin or chgcode or enter or clear or key1 or key2; ifnum=not(one_key(3) and (one_key(2) or

10、 one_key(1); -ifnum=1,the key is a num o_ua=s_ua;-表明当前状态为管理员或是用户 chgcode_ua=c_ua;-表明当前更改的密码为用户密码或是管理员密码 o_chgcode=chg_c;-当状态为“1”时表明正在修改密码 out_code4=out_code; alarming=alarm; main:PROCESS(res,clk) variable n,m:std_logic_vector(1 downto 0):=00; variable new1_code,new2_code:std_logic_vector(15 downto 0

11、); BEGIN if (res=1)then state=ss;-出厂状态,用来初始化密码锁的各项设置 user_code=0001001000110100;-1234 admin_code=0000000000000000;-0000 n:=00; s_ua=0; c_ua=0; chg_c=0; new_ctime=00; alarm state if back=1 then state=sw; elsif (ifnum=1 and alarm=0 and chg_c=0 ) then code3=one_key; out_code=0001; state=s1; elsif (ifnu

12、m=1 and c_ua=0 and chg_c=1 ) then old_code=user_code; code3=one_key; out_code=0001; state=s1; elsif (ifnum=1 and alarm=1 and s_ua=1 and chg_c=0 ) then code3=one_key; out_code=0001; state=s1; elsif (ifnum=1 and c_ua=1 and chg_c=1 ) then old_code=admin_code; code3=one_key; out_code=0001; state=s1; els

13、if (one_key=0011and chg_c=0 )then s_ua=1; state=s0; elsif (one_key=0100and chg_c=0 and alarm=0) then s_ua=0; state if back=1 then state=sw; elsif(ifnum=1)then code2=one_key; out_code=0011; state=s2; elsif (one_key=0000)then -clear out_code=0000; state=s0; elsif (one_key=0100 and chg_c=0) then -user

14、out_code=0000; s_ua=0; state=s0; elsif (one_key=0011 and chg_c=0) then -admin out_code=0000; s_ua=1; state if back=1 then state=sw; elsif(ifnum=1)then code1=one_key; out_code=0111; state=s3; elsif (one_key=0000)then out_code=0001; state=s1; elsif (one_key=0100 and chg_c=0) then out_code=0000; s_ua=0

15、; state=s0; elsif (one_key=0011 and chg_c=0) then out_code=0000; s_ua=1; state if back=1 then state=sw; elsif(ifnum=1)then code0=one_key; out_code=1111; state=s4; elsif (one_key=0000)then out_code=0011; state=s2; elsif (one_key=0100 and chg_c=0) then out_code=0000; s_ua=0; state=s0; elsif (one_key=0

16、011 and chg_c=0) then out_code=0000; s_ua=1; state if back=1 then state=sw; elsif (one_key=0001 and chg_c=0)then -enter state=s5; out_code=0000; elsif (one_key=0001 and chg_c=1and m=00)then -enter out_code=0000; if (old_code=temp_code) then m:=01; state=s0; else state=sw; end if; elsif (one_key=0001

17、 and chg_c=1and m=01)then -enter out_code=0000; new1_code:=temp_code; m:=10; state=s0; elsif (one_key=0001 and chg_c=1and m=10)then -enter out_code=0000; new2_code:=temp_code; if (new1_code=new2_code and c_ua=0) then user_code=new2_code; state=sw; elsif(new1_code=new2_code and c_ua=1)then admin_code

18、=new2_code; state=sw; elsif(new1_code/=new2_code) then state=sw; end if; elsif (one_key=0000)then -clear out_code=0111; state if (s_ua=0 and temp_code=user_code) then openlock=1; state=s6; elsif (s_ua=0and temp_code/=user_code) then n:=n+1; if n=11 then alarm=1; state=s0; out_code=0000; else state=s

19、0; out_code=0000; end if; elsif (s_ua=1 and temp_code=admin_code) then state=s6; elsif(s_ua=1 and temp_code/=admin_code) then state if back=1 then state=sw; elsif(one_key=0001)then-enter state=sw; elsif(one_key=0000and alarm=1) then -clear alarm=0; state=s0; out_code=0000; elsif(one_key=0010) then c

20、hg_c=1; state m:=00; if back=1 then state=sw; elsif(one_key=0100)then c_ua=0; old_code=user_code; state=s0; elsif(one_key=0011)then c_ua=1; old_code=admin_code; state alarm=0; s_ua=0; c_ua=0; m:=00; n:=00; openlock=0; out_code=0000; chg_c=0; stateone_keyone_keyone_keyone_keyone_keyone_keyone_keyone_

21、keyone_key=1111; END CASE; end if;END PROCESS INPUT;PROCESS(inkey,res,clk,alarm,openlock)variable numtime:std_logic_vector(5 downto 0):=000000;BEGINif(res=1) then numtime:=000000; back=0;elsif (openlock=1 or inkey=1)or alarm=1) then back=0; numtime:=000000;elsif (clkevent and clk=1)and inkey=0 and a

22、larm=0 and openlock=0)then numtime:=numtime+1; if numtime=111100 then back=1; numtime:=000000; end if;end if;end process ; END behave;实验小结这次为期2周的EDA实验,对于这次的VHDL4位密码锁设计对我来说是个很大的挑战,以前的EDA知识就不是太牢靠,再加上一个假期没有碰过EDA的书,所以这次为期2个星期的密码锁实验对于我来说真的很棘手,刚开始做实验的时候,一点头脑都摸不着,不知道从何下手,后来通过上网查资料和与同学的讨论才开始慢慢的理清头绪,这次试验对编程语言的要求很高,这是我进一步确定了要学好C语言的决心,这次试验对我来说是个挑战,但当我克服他的时候,一种成就感就会油然而生,通过这次实验,我学到了很多东西,增强了我的动手能力。

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

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


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号