VHDL四位密码锁课程设计EDA2_第1页
VHDL四位密码锁课程设计EDA2_第2页
VHDL四位密码锁课程设计EDA2_第3页
VHDL四位密码锁课程设计EDA2_第4页
VHDL四位密码锁课程设计EDA2_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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

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

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

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

5、返回等待状态。成功后也返回等待状态。定时返回:用户在未开锁状态下,60s没有按键输入,则返回等待状态,但不包括alarmsignaling状态。只要是alarmsignaling,则只有管理输入管理员密码才能解锁并按下clear消除警报。设计内容(原理图以及相关说明、调试过程、结果)设计思路:设计密码锁时,采用自顶向下的设计方法。将整个系统分成几个子模块:输入输出模块,控制模块,按键设置模块和60s计时器模块。 控制模块是整个程序的主要部分,采用状态循环的办法,以用户每按下一次按键为计量单位,划分状态,以实现各种功能。60s计时器模块是完成60s没有按键则返回等待状态这一功能的主要模块。这个模

6、块的核心思想是一个变量numtime计数。变量numtime的初始值为0,在无报警为开锁的情况下,时钟每秒发出一个上升沿信号,计数一次,如有按键则numtime清零,否则计数到60即“111100”则返回信号back变为1,返回等待状态。按键设置模块是将各种功能按键用高低电平赋值,便于调用。程序设计:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity e_lock is port( clk,user,admin,clear,enter,chgcode,res:in std_logic;

7、num:in std_logic_vector(9 downto 0); lockopen:buffer std_logic; alarmsignaling,o_ua,o_chgcode,chgcode_ua:out std_logic; outcode6: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,s8,s9);signal state:states;signal key1,code0,co

8、de1,code2,code3,code4,code5:std_logic_vector(3 downto 0);signal userpassword,adminpassword:std_logic_vector(23 downto 0);signal tempcode,oldcode:std_logic_vector(23 downto 0);signal new_ctime:std_logic_vector(1 downto 0);signal key:std_logic_vector(14 downto 0);signal alarmsignal,inkey,ifnum,s_ua,ch

9、g_c,c_ua,back:std_logic;signal outcode:std_logic_vector(5 downto 0);signal numtime:std_logic_vector(9 downto 0);begin tempcode=code0&code1&code2&code3&code4&code5; key=user&admin&chgcode&enter&clear# inkey=user or admin or chgcode or enter or clear or num(0) or num(1) or num(2) or num(3) or num(

10、4) or num(5) or num(6) or num(7) or num(8) or num(9); ifnum=not(key1(3) and (key1(2) or key1(1); o_ua=s_ua; chgcode_ua=c_ua; o_chgcode=chg_c; outcode6=outcode; alarmsignaling=alarmsignal; main:process(res,clk) variable n,m:std_logic_vector(1 downto 0):=00; variable newcode1,newcode2:std_logic_vector

11、(23 downto 0); begin if (res=1)then state=ss; userpassword=100110011001100110011001; adminpassword=000000000000000000000000; n:=00; s_ua=0; c_ua=0; chg_c=0; new_ctime=00; alarmsignal state if back=1 then state=sw; elsif (ifnum=1 and alarmsignal=0 and chg_c=0 ) then code5=key1; outcode=0001; state=s1

12、; elsif (ifnum=1 and c_ua=0 and chg_c=1 ) then oldcode=userpassword; code5=key1; outcode=0001; state=s1; elsif (ifnum=1 and alarmsignal=1 and s_ua=1 and chg_c=0 ) then code5=key1; outcode=0001; state=s1; elsif (ifnum=1 and c_ua=1 and chg_c=1 ) then oldcode=adminpassword; code5=key1; outcode=0001; st

13、ate=s1; elsif (key1=1101and chg_c=0 )then s_ua=1; state=s0; elsif (key1=1110and chg_c=0 and alarmsignal=0) then s_ua=0; state if back=1 then state=sw; elsif(ifnum=1)then code4=key1; outcode=0011; state=s2; elsif (key1=1010)then outcode=0000; state=s0; elsif (key1=1110 and chg_c=0) then outcode=0000;

14、 s_ua=0; state=s0; elsif (key1=1101 and chg_c=0) then outcode=0000; s_ua=1; state if back=1 then state=sw; elsif(ifnum=1)then code3=key1; outcode=0111; state=s3; elsif (key1=1010)then outcode=0001; state=s1; elsif (key1=1110 and chg_c=0) then outcode=0000; s_ua=0; state=s0; elsif (key1=1101 and chg_

15、c=0) then outcode=0000; s_ua=1; state if back=1 then state=sw; elsif(ifnum=1)then code2=key1; outcode=1111; state=s4; elsif (key1=1010)then outcode=0011; state=s2; elsif (key1=1110 and chg_c=0) then outcode=0000; s_ua=0; state=s0; elsif (key1=1101 and chg_c=0) then outcode=0000; s_ua=1; state if bac

16、k=1 then state=sw; elsif(ifnum=1)then code1=key1; outcode=1111; state=s5; elsif (key1=1010)then outcode=0111; state=s3; elsif (key1=1110 and chg_c=0) then outcode=0000; s_ua=0; state=s0; elsif (key1=1101 and chg_c=0) then outcode=0000; s_ua=1; state if back=1 then state=sw; elsif(ifnum=1)then code0=

17、key1; outcode=1111; state=s6; elsif (key1=1010)then outcode=1111; state=s4; elsif (key1=1110 and chg_c=0) then outcode=0000; s_ua=0; state=s0; elsif (key1=1101 and chg_c=0) then outcode=0000; s_ua=1; state if back=1 then state=sw; elsif (key1=1011 and chg_c=0)then state=s7; outcode=0000; elsif (key1

18、=1011 and chg_c=1and m=00)then outcode=0000; if (oldcode=tempcode) then m:=01; state=s0; else state=sw; end if; elsif (key1=1011 and chg_c=1and m=01)then outcode=0000; newcode1:=tempcode; m:=10; state=s0; elsif (key1=1011 and chg_c=1and m=10)then outcode=0000; newcode2:=tempcode; if (newcode1=newcod

19、e2 and c_ua=0) then userpassword=newcode2; state=sw; elsif(newcode1=newcode2 and c_ua=1)then adminpassword=newcode2; state=sw; elsif(newcode1/=newcode2) then state=sw; end if; elsif (key1=1010)then outcode=1111; state if (s_ua=0 and tempcode=userpassword) then lockopen=1; state=s8; elsif (s_ua=0and

20、tempcode/=userpassword) then n:=n+1; if n=11 then alarmsignal=1; state=s0; outcode=0000; else state=s0; outcode=0000; end if; elsif (s_ua=1 and tempcode=adminpassword) then state=s8; elsif(s_ua=1 and tempcode/=adminpassword) then state if back=1 then state=sw; elsif(key1=1011)then-enter state=sw; el

21、sif(key1=1010and alarmsignal=1) then alarmsignal=0; state=s0; outcode=0000; elsif(key1=1100) then chg_c=1; state m:=00; if back=1 then state=sw; elsif(key1=1110)then c_ua=0; oldcode=userpassword; state=s0; elsif(key1=1101)then c_ua=1; oldcode=adminpassword; state alarmsignal=0; s_ua=0; c_ua=0; m:=00; n:=00; lockopen=0; outcode=0000; chg_c=0; statekey1key1key1key1key1key1key1key1key1key1key1key1key1key1key1key1=1111; end case; end if;end process input;process(inkey,res,clk,alarmsignal,lockopen)variable numtime:s

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论