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

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

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

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

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

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

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

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

6、为0,在无报警为开锁的情况下,时钟每秒发出一个上升沿信号,计数一次,如有按键则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;- Uncomment the following library declaration if instantiating- any Xilinx pr

7、imitives in this code.-library UNISIM;-use UNISIM.VComponents.all;entity lock isPORT( clk,user,admin,clear,enter,chgcode,res,numenter ,number:IN STD_LOGIC; openlock:buffer std_logic; alarming,model:OUT STD_LOGIC; shuma2,shuma1,shuma0:out std_logic_vector(6 downto 0) );end lock;architecture Behaviora

8、l of lock isTYPE STATES IS (sw,s1,s2,s3,s4,s5,s6,s7);SIGNAL state:STATES;SIGNAL one_key,code0,code1,code2:STD_LOGIC_VECTOR(3 DOWNTO 0);SIGNAL user_code,admin_code:STD_LOGIC_VECTOR(11 DOWNTO 0);SIGNAL temp_code,old_code:STD_LOGIC_VECTOR(11 DOWNTO 0);SIGNAL key:std_logic_vector(3 downto 0);signal alar

9、m,ifnum,s_model,chg_c,c_ua:std_logic;signal k :std_logic_vector(3 downto 0); begin temp_code=code2&code1&code0; model=s_model; alarming=alarm;main:PROCESS(res,admin,user,clear,chgcode,number,numenter,enter) variable n,m:std_logic_vector(1 downto 0):=00;variable new1_code,new2_code:std_logic_vector(1

10、1 downto 0); BEGIN if (res=1) then state=s1;-出厂状态 user_code=001000010001;-211 admin_code=001000010000;-210 n:=00; s_model=0; c_ua=0; chg_c=0; K=0000; openlock=0; alarm=0; shuma2=0000000; shuma1=0000000; shuma0=0000000; ifnum=0; else if (number=1) then k=k+1; Elsif numenter=1 then ifnum if ( admin=1

11、and chg_c=0 )then s_model=1; state=s1; elsif (user=1 and chg_c=0 and alarm=0) then s_model=0; state=s1; elsif (ifnum=1 and alarm=0 and chg_c=0 ) then code2=k; ifnumshuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2=0000000; END CASE; k=0000; state=s2; elsif (ifnum=1 and c_u

12、a=0 and chg_c=1 ) then old_code=user_code; code2=k; ifnumshuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2=0000000; END CASE; k=0000; state=s2; elsif (ifnum=1 and alarm=1 and s_model=1 and chg_c=0 ) then code2=k; ifnumshuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2

13、 shuma2 shuma2 shuma2=0000000; END CASE; k=0000; state=s2; elsif (ifnum=1 and c_ua=1 and chg_c=1 ) then old_code=admin_code; code2=k; ifnumshuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2 shuma2=0000000; END CASE; k=0000; state=s2; elsif (clear=1)then -clear state if (user=1 and

14、 chg_c=0) then -user s_model=0; state=s1; elsif (admin=1 and chg_c=0) then -admin s_model=1; state=s1; elsif(ifnum=1)then code1=k; ifnumshuma1 shuma1 shuma1 shuma1 shuma1 shuma1 shuma1 shuma1 shuma1 shuma1 shuma1=0000000; END CASE; k=0000; state=s3; elsif (clear=1)then -clear state if(user=1 and chg

15、_c=0) then s_model=0; state=s1; elsif (admin=1 and chg_c=0) then s_model=1; state=s1; elsif (ifnum=1)then code0=k; ifnumshuma0 shuma0 shuma0 shuma0 shuma0 shuma0 shuma0 shuma0 shuma0 shuma0 shuma0=0000000; END CASE; k=0000; state=s4; elsif(clear=1)then state if (enter=1 and chg_c=0)then -enter state

16、=s5; elsif (enter=1 and chg_c=1and m=00)then -enter if (old_code=temp_code) then m:=01; state=s1; else state=sw; end if; elsif (enter=1 and chg_c=1and m=01)then -enter new1_code:=temp_code; m:=10; state=s1; elsif (enter=1 and chg_c=1and m=10)then -enter new2_code:=temp_code; if (new1_code=new2_code

17、and c_ua=0) then user_code=new2_code; state=sw; elsif(new1_code=new2_code and c_ua=1)then admin_code=new2_code; state=sw; elsif(new1_code/=new2_code) then state=sw; end if; elsif(clear=1)then state if (s_model=0 and temp_code=user_code) then openlock=1; state=s6; elsif (s_model=0and temp_code/=user_code) then n:=n+1; if n=11 then alarm=1; state=s1; else state=s1; end if; elsif (s_model=1 and temp_code=admin_code) then state=s6; elsif(s_model=1 and temp_code/=admin_code) then state if(enter=1)then-enter state=sw; elsif(clear=1 and alarm=1) then -clear alarm=0;

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

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


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号