首页 VHDL密码锁

VHDL密码锁

举报
开通vip

VHDL密码锁电子与信息工程学院 EDA课程设计与实现报告 ( 2011 — 2012 学年 第 一 学期) 班    级:____________ 学    号:_________________ 姓    名:_______________ 指导教师:          ____ 2011 年  9  月 课程设计题目:EDA课程设计与实现 内容和要求: 实验内容:           1. 掌握VHDL语言的使用,学会用VHDL语言来编程解决实际问题;           2. 学会使用EDA开发软件设计小型综合电...

VHDL密码锁
电子与信息工程学院 EDA课程设计与实现 报告 软件系统测试报告下载sgs报告如何下载关于路面塌陷情况报告535n,sgs报告怎么下载竣工报告下载 ( 2011 — 2012 学年 第 一 学期) 班    级:____________ 学    号:_________________ 姓    名:_______________ 指导教师:          ____ 2011 年  9  月 课程设计 快递公司问题件快递公司问题件货款处理关于圆的周长面积重点题型关于解方程组的题及答案关于南海问题 目:EDA课程设计与实现 内容和要求: 实验内容:           1. 掌握VHDL语言的使用,学会用VHDL语言来编程解决实际问题;           2. 学会使用EDA开发软件设计小型综合电路,掌握仿真的技巧;           3. 学会应用开发系统实现硬件电路,检验电路的功能。 实验要求:           用VHDL语言设计一个密码锁,用波形仿真验证其功能后,实现到GW48实验系统。 功能描述:           用于模仿密码锁的工作过程。完成密码锁的核心控制功能。 功能要求:           设计一个密码锁,平时处于等待状态。管理员可以设置或更改密码。如果不预置密码,密码缺省为“0000”。用户如果需要开锁,按相应的按键进入输入密码状态,输入4位密码,按下确定键后,若密码正确,锁打开;若密码错误,将提示密码错误,要求重新输入,三次输入都错误,将发出报警信号。报警后,只有管理员作相应的处理才能停止报警。用户输入密码时,若输入错误,在按下确定键之前,可以通过按取消键重新输入。正确开锁后,用户处理完毕后,按下确定键,系统回到等待状态。系统操作过程中,只要密码锁没有打开,如果60秒没有对系统操作,系统回到等待状态。要求密码在输入过程中被依次显示,即先输入的为密码的第一位,总是显示在最左边。用两个发光二极管模拟显示,其中一个显示当前的工作模式,灭表示用户模式,亮表示管理员模式;另外一个指示锁的状态,灭表示锁处于锁定,亮表示锁被开启。用两个按键实现密码输入,Key1表示密码“1”,KEY2表示密码“0”。  功能描述:       初始状态:初次使用密码锁时,要先用Reset键初始化。初始状态下,用户密码为“1111”,管理员密码为“0000”。       用户开锁:默认情况下,密码锁处于用户使用状态。如果当前为管理员状态,则按下user键回到用户状态。用户开锁时,输入四位数用户密码,可以从out_code6的输出状态确定密码输入状态。如输入错误则按下clear清除前一位输入。输入完毕后按enter,如果密码正确,则开锁,否则重新输入密码。开锁后再次按下enter键则关锁,回到等待状态。三次密码输入错误,警报器alarming为1。要管理员输入管理员密码解除警报。此时哪怕用户再输对密码也没用。       管理员解除警报:当用户三次密码输入错误的时候,alarming为1,此时,只要管理员密码输入正确后,按下clear键,alarming为0,报警取消。       管理员修改密码:在非警报和为开锁状态下,任何时候按admin键进入管理员状态。按chgcode选择修改密码,先选择修改的是用户密码还是管理员密码。修改用户密 码则按user键,修改管理员密码则按admin键。然后分别输入旧密码,新密码,新密码 要输入两次。旧密码与所要修改的密码对应。如旧密码输入错误,则无法修改;当验证不成功即两次新密码不相同时,修改密码失败。返回等待状态。成功后也返回等待状态。     定时返回:用户在未开锁状态下,60s没有按键输入,则返回等待状态,但不包括alarming状态。只要是alarming,则只有管理输入管理员密码才能解锁并按下clear消除警报。 设计思路:       设计密码锁时,采用自顶向下的设计方法。将整个系统分成几个子模块:输入输出模块,控制模块,按键设置模块和60s计时器模块。       控制模块是整个程序的主要部分,采用状态循环的办法,以用户每按下一次按键为计量单位,划分状态,以实现各种功能。       60s计时器模块是完成60s没有按键则返回等待状态这一功能的主要模块。这个模块的核心思想是一个变量numtime计数。变量numtime的初始值为0,在无报警为开锁的情况下,时钟每秒发出一个上升沿信号,计数一次,如有按键则numtime清零,否则计数到60即“111100”则返回信号back变为1,返回等待状态。       按键设置模块是将各种功能按键用高低电平赋值,便于调用。 设计内容(原理图以及相关说明、调试过程、结果) 程序设计: LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_UNSIGNED.ALL; USE IEEE.STD_LOGIC_ARITH.ALL; ENTITY E_lock IS PORT(       clk,user,admin,clear,enter,chgcode,res:IN STD_LOGIC;       key1:IN STD_LOGIC;       key2:IN STD_LOGIC;       openlock:buffer std_logic;       alarming,o_ua,o_chgcode,chgcode_ua:OUT STD_LOGIC;       out_code0:out std_logic_vector(3 downto 0);       out_code1:out std_logic_vector(3 downto 0);       out_code2:out std_logic_vector(3 downto 0);       out_code3:out std_logic_vector(3 downto 0)); END E_lock; ARCHITECTURE behavior OF E_lock IS TYPE STATES IS (ss,sw,s0,s1,s2,s3,s4,s5,s6,s7); SIGNAL state:STATES; SIGNAL one_key,code0,code1,code2,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(6 downto 0);                            SIGNAL alarm,inkey,ifnum,s_ua,chg_c,c_ua,back:std_logic;                                              BEGIN      temp_code<=code0&code1&code2&code3;   key<=user&admin&chgcode&enter&clear&key1&key2;   inkey<=user or admin or chgcode or enter or clear or key1 or key2;   ifnum<=not(one_key(3) or one_key(2) or one_key(1));                        o_ua<=s_ua;   chgcode_ua<=c_ua;   o_chgcode<=chg_c;   alarming<=alarm;   out_code0 <= code0;   out_code1 <= code1;   out_code2 <= code2;   out_code3 <= code3;   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);   BEGIN     if (res='1')then           state<=ss;           user_code<="0001000100010001";           admin_code<="0000000000000000";           n:="00";           s_ua<='0';           c_ua<='0';           chg_c<='0';           alarm<='0';     elsif clk'EVENT AND clk='1' then           case state is     when ss=>           state<=s0;     when s0=>             if back='1' then                 state<=sw;             elsif (ifnum='1' and alarm='0'  and chg_c='0' ) then                 code3<=one_key;                 state<=s1;             elsif (ifnum='1'  and c_ua='0' and chg_c='1' ) then                 old_code<=user_code;                 code3<=one_key;                 state<=s1;             elsif (ifnum='1' and alarm='1' and s_ua='1' and chg_c='0' ) then                 code3<=one_key;                 state<=s1;             elsif (ifnum='1'  and c_ua='1' and chg_c='1' ) then                 old_code<=admin_code;                 code3<=one_key;                 state<=s1;             elsif (one_key="1101"and chg_c='0' )then                 s_ua<='1';                 state<=s0;             elsif (one_key="1110"and chg_c='0' and alarm='0') then                 s_ua<='0';                 state<=s0;             end if;     when s1=>             if back='1' then                 state<=sw;             elsif(ifnum='1')then                 code2<=one_key;                 state<=s2;             elsif (one_key="1010")then                 state<=s0;             elsif (one_key="1110" and chg_c='0') then                 s_ua<='0';                 state<=s0;             elsif (one_key="1101"  and chg_c='0') then                                  s_ua<='1';                 state<=s0;              end if;     when s2=>             if back='1'  then                 state<=sw;             elsif(ifnum='1')then                 code1<=one_key;                 state<=s3;             elsif (one_key="1010")then                 state<=s1;             elsif (one_key="1110" and chg_c='0') then                 s_ua<='0';                 state<=s0;             elsif (one_key="1101" and chg_c='0') then                 s_ua<='1';                 state<=s0;                end if;     when s3=>             if back='1'  then                 state<=sw;             elsif(ifnum='1')then                 code0<=one_key;                 state<=s4;             elsif (one_key="1010")then                  state<=s2;             elsif (one_key="1110" and chg_c='0') then                 s_ua<='0';                 state<=s0;             elsif (one_key="1101" and chg_c='0') then                 s_ua<='1';                 state<=s0;                end if;                             when s4=>             if back='1'  then                 state<=sw;             elsif (one_key="1011" and chg_c='0')then                 state<=s5;             elsif (one_key="1011" and chg_c='1'and m="00")then                       if (old_code=temp_code) then                       m:="01";                       state<=s0;                       else state<=sw;                       end if;             elsif (one_key="1011" and chg_c='1'and m="01")then                       new1_code:=temp_code;                       m:="10";                       state<=s0;             elsif (one_key="1011" and chg_c='1'and m="10")then                       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<=new2_code;                             state<=sw;                       elsif(new1_code/=new2_code) then                             state<=sw;                       end if;             end if;        when s5=>             if (s_ua='0' and temp_code=user_code) then                 openlock<='1';                 state<=s6;             elsif (s_ua='0'and temp_code/=user_code) then                 n:=n+1;                 if n="11" then                       alarm<='1';                       state<=s0;                 else                       state<=s0;                     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<=sw;             end if;     when s6=>             if back='1'  then                 state<=sw;             elsif(one_key="1011")then                 state<=sw;             elsif(one_key="1010"and alarm='1') then                 alarm<='0';                 state<=s0;             elsif(one_key="1100") then                 chg_c<='1';                 state<=s7;             end if;                           when s7=>             m:="00";             if back='1'  then                 state<=sw;             elsif(one_key="1110")then                 c_ua<='0';                 old_code<=user_code;                 state<=s0;             elsif(one_key="1101")then                 c_ua<='1';                 old_code<=admin_code;                 state<=s0;             end if;       when sw=>             alarm<='0';             s_ua<='0';             c_ua<='0';             m:="00";             n:="00";             openlock<='0';             chg_c<='0';             state<=s0;                   end case;     END if;   END PROCESS main; INPUT:PROCESS(clk) BEGIN   if clk'event and clk='0' then   CASE key IS   WHEN "0000001"=>one_key<="0000";   WHEN "0000010"=>one_key<="0001";   WHEN "0000100"=>one_key<="1010";   WHEN "0001000"=>one_key<="1011";   WHEN "0010000"=>one_key<="1100";   WHEN "0100000"=>one_key<="1101";   WHEN "1000000"=>one_key<="1110";   WHEN OTHERS  =>one_key<="1111";   END CASE; end if; END PROCESS INPUT; PROCESS(inkey,res,clk,alarm,openlock) variable numtime:std_logic_vector(5 downto 0):="000000"; BEGIN if(res='1') then     numtime:="000000";     back<='0'; elsif ((openlock='1' or inkey='1')or alarm='1') then     back<='0';     numtime:="000000"; elsif ((clk'event and clk='1')and inkey='0' and alarm='0' and openlock='0')then     numtime:=numtime+1;     if numtime="111100" then           back<='1';           numtime:="000000";     end if; end if; end process ; END behavior; 测试代码及仿真图 1.输入密码打开电子锁       res <='0','1' after 10 ns,'0' after 20 ns;                 user <='0';                 admin <='0';                 clear <='0';               chgcode <='0';         enter <='0','1' after 180 ns,'0' after 190 ns,                 '1' after 250 ns,'0' after 260 ns;                                         key1 <='0','1' after 100 ns,'0' after 110 ns,                 '1' after 120 ns,'0' after 130 ns,                 '1' after 140 ns,'0' after 150 ns,                 '1' after 160 ns,'0' after 170 ns;             key2 <='0'; 仿真结果为: 2.第一次输入密码错误,第二次正确输入打开电子锁         res <='0','1' after 10 ns,'0' after 20 ns;                 user <='0';                 admin <='0';                 clear <='0';                 enter <='0',                         '1' after 180 ns,'0' after 190 ns,                         '1' after 280 ns,'0' after 290 ns,                         '1' after 340 ns,'0' after 350 ns;                                     chgcode <='0';                 key1 <='0',                                             '1' after 100 ns,'0' after 110 ns,                       '1' after 120 ns,'0' after 130 ns,                                                                           '1' after 200 ns,'0' after 210 ns,                       '1' after 220 ns,'0' after 230 ns,                       '1' after 240 ns,'0' after 250 ns,                       '1' after 260 ns,'0' after 270 ns;                                 key2 <='0',                                             '1' after 140 ns,'0' after 150 ns,                       '1' after 160 ns,'0' after 170 ns;   仿真结果为: 3.clear 清除键测试代码       res <='0','1' after 10 ns,'0' after 20 ns;                 user <='0';                 admin <='0';                 chgcode <='0';                 clear <='0','1' after 140 ns,'0' after 150 ns;                 enter <='0','1' after 220 ns,'0' after 230 ns;                                 key1 <='0','1' after 100 ns,'0' after 110 ns,                 '1' after 160 ns,'0' after 170 ns,                 '1' after 180 ns,'0' after 190 ns,                 '1' after 200 ns,'0' after 210 ns;                               key2 <='0','1' after 120 ns,'0' after 130 ns; 4.管理员修改用户密码,新密码为1010       res <='0','1' after 10 ns,'0' after 20 ns;                 user <='0','1' after 240 ns,'0' after 250 ns;                 admin <='0','1' after 100 ns,'0' after 110 ns;                 clear <='0';       chgcode <='0','1' after 220 ns,'0' after 230 ns;                 enter <='0','1' after 200 ns,'0' after 210 ns,                 '1' after 340 ns,'0' after 350 ns,                 '1' after 440 ns,'0' after 450 ns,                 '1' after 540 ns,'0' after 550 ns,                 '1' after 630 ns,'0' after 640 ns;                 key1 <='0','1' after 260 ns,'0' after 270 ns,                   '1' after 280 ns,'0' after 290 ns,                   '1' after 300 ns,'0' after 310 ns,                   '1' after 320 ns,'0' after 330 ns,                                         '1' after 360 ns,'0' after 370 ns,                   '1' after 400 ns,'0' after 410 ns,                                       '1' after 460 ns,'0' after 470 ns,                 '1' after 500 ns,'0' after 510 ns,                                       '1' after 560 ns,'0' after 570 ns,                 '1' after 600 ns,'0' after 610 ns;                               key2 <='0','1' after 120 ns,'0' after 130 ns,                   '1' after 140 ns,'0' after 150 ns,                     '1' after 160 ns,'0' after 170 ns,                     '1' after 180 ns,'0' after 190 ns,                                           '1' after 380 ns,'0' after 390 ns,                     '1' after 420 ns,'0' after 430 ns,                                           '1' after 480 ns,'0' after 490 ns,                     '1' after 520 ns,'0' after 530 ns,                                             '1' after 580 ns,'0' after 590 ns,                     '1' after 620 ns,'0' after 630 ns; 仿真结果为:   5.输入错误密码三次,警报响,管理员输入管理员密码按下clear键解除警报       res <='0','1' after 10 ns,'0' after 20 ns;                 user <='0';                 admin <='0','1' after 420 ns,'0' after 430 ns;                 clear <='0','1' after 540 ns,'0' after 550 ns;       chgcode <='0';                 enter <='0',                         '1' after 180 ns,'0' after 190 ns,                         '1' after 280 ns,'0' after 290 ns,                         '1' after 380 ns,'0' after 390 ns,                         '1' after 520 ns,'0' after 530 ns;                 key1 <='0',                                             '1' after 100 ns,'0' after 110 ns,                       '1' after 120 ns,'0' after 130 ns,                                             '1' after 240 ns,'0' after 250 ns,                       '1' after 260 ns,'0' after 270 ns,                                             '1' after 300 ns,'0' after 310 ns,                       '1' after 340 ns,'0' after 350 ns;                                 key2 <='0',                                             '1' after 140 ns,'0' after 150 ns,                       '1' after 160 ns,'0' after 170 ns,                                             '1' after 200 ns,'0' after 210 ns,                       '1' after 220 ns,'0' after 230 ns,                                             '1' after 320 ns,'0' after 330 ns,                       '1' after 360 ns,'0' after 370 ns,                                                                   '1' after 440 ns,'0' after 450 ns,                       '1' after 460 ns,'0' after 470 ns,                       '1' after 480 ns,'0' after 490 ns,                       '1' after 500 ns,'0' after 510 ns; 仿真结果为: 实验小结     这次EDA课程设计历时两周,可以说是苦多于甜,但是可以学到很多很多的东西,不仅可以巩固以前所学过的知识,而且学到了很多在书本上所没有学到过的知识。通过这次设计,进一步加深了对EDA的了解,让我们对它有了更加浓厚的兴趣。特别是当模块编写调试成功时,心里特别的开心。但是在测试程序时,遇到了不少问题,在细心的专研下,终于找出程序的语法和逻辑错误,程序编译就通过了,心里终于舒了一口气。但当波形仿真时,我彻底难住了,想要的结果不能在波形上得到正确的显示。后来,在测试平台上无数的调试之后,才发现是因为输入的信号对于器件的延迟时间控制得不对。经过屡次调试,终于得出理想的仿真波形图。     通过这次课程设计使我们懂得了理论与实际相结合是很重要的,只有理论知识是远远不够的,只有把所学的理论知识与实践相结合起来,从理论中得出结论,才能真正为社会服务,从而提高自己的实际动手能力和独立思考的能力。在设计的过程中遇到问题,可以说得是困难重重,这毕竟第一次做的,难免会遇到过各种各样的问题,同时在设计的过程中发现了自己的不足之处,对以前所学过的知识理解得不够深刻,掌握得不够牢固。     总的来说,这次设计还是比较成功的,在设计中遇到了很多问题,最后在老师的辛勤的指导下,终于游逆而解,有点小小的成就感,终于觉得平时我们现在的能力还远远不够,必须要理论与实际相结合。这次实习不仅学到了不少知识,而且锻炼了自己的能力,使自己对以后的路有了更加清楚的认识,同时,对未来有了更加详细的目标。最后,对给过我帮助的所有同学和各位指导老师再次表示忠心的感谢!
本文档为【VHDL密码锁】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_044822
暂无简介~
格式:doc
大小:160KB
软件:Word
页数:14
分类:生活休闲
上传时间:2017-09-19
浏览量:22