vhdl密码锁.docx
- 文档编号:13207483
- 上传时间:2023-06-12
- 格式:DOCX
- 页数:18
- 大小:448.94KB
vhdl密码锁.docx
《vhdl密码锁.docx》由会员分享,可在线阅读,更多相关《vhdl密码锁.docx(18页珍藏版)》请在冰点文库上搜索。
vhdl密码锁
Vhdl短学期实验——密码锁设计
小组成员:
04008230李黎
04008228陈宗渊
04008211周炳宇
一、课题描述:
用于模仿密码锁的工作过程。
完成密码锁的核心控制功能。
二、功能要求:
设计一个密码锁,平时处于等待状态。
管理员可以设置或更该密码。
如果不预置密码,密码缺省为“999999”。
用户如果需要开锁,按相应的按键进入输入密码状态,输入6位密码,按下确定键后,若密码正确,锁打开,若密码错误,将提示密码错误,要求重新输入,三次输入都错误,将发出报警信号。
报警后,只有管理员作相应的处理才能停止报警。
用户输入密码时,若输入错误,在按下确定键之前,可以通过按取消键重新输入。
正确开锁后,用户处理完毕后,按下确定键,系统回到等待状态。
系统操作过程中,只要密码锁没有打开,如果60秒没有对系统操作,系统回到等待状态。
注意:
输入按键信号时必须一个按键一个按键输入,不得6个按键一起输入。
三、设计流程:
1.结构框图:
①按键输入;
②复位(设置缺省密码);
③等待状态
④工作状态
⑤修改密码
⑥提醒错误及报警
⑦开锁
⑧恢复等待
2.模块设计:
★控制模块:
实现输入输出,实现等待工作的转换,实现开锁及报警;
★比较模块:
比较输入密码与正确密码
★寄存模块:
存放密码
★计数及使能模块:
(1)输入个数为6,多于无效自动忽略;
(2)60s的空闲时间,无操作返回等待;
(3)错误次数为3
(4)进入工作状态,是能段即打开,直到进入等待。
四、具体实现:
★控制模块:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityctrlis
port
(change,vers,keysign:
instd_logic;
ok,cancel:
instd_logic;
clk:
instd_logic;
result:
instd_logic;
wt:
instd_logic;
enable:
outstd_logic
);
endctrl;
architecturectrl_behaveofctrlis
signalsec:
integerrange0to60;
begin
process(clk)
begin
if(clk'eventandclk='1')then
if(vers='1')then
enable<='1';
endif;
if(wt='1'andresult='1')then
enable<='0';
sec<=0;
endif;
if(change='0'andvers='0'andkeysign='0'andok='0'andcancel='0')then
sec<=sec+1;
if(sec=59)then
enable<='0';
sec<=0;
endif;
else
sec<=0;
endif;
endif;
endprocess;
endctrl_behave;
★比较模块:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityveris
port
(dt1,dt2,dt3,dt4,dt5,dt6:
instd_logic_vector(3downto0);
cd1,cd2,cd3,cd4,cd5,cd6:
instd_logic_vector(3downto0);
vers:
instd_logic;
ready:
instd_logic;
clk:
instd_logic;
stopalarm:
instd_logic;
en:
instd_logic;
result:
outstd_logic;
wrong:
outstd_logic;
alarm:
outstd_logic
);
endver;
architecturever_behaveofveris
signalalarmnum:
integerrange0to3;
signalvering:
std_logic;
signalwronging:
std_logic;
begin
process(clk)
begin
if(clk'eventandclk='1')then
if(en='0')then
result<='0';
endif;
if(stopalarm='1')then
alarmnum<=0;
endif;
if(wronging='1')then
wronging<='0';
vering<='1';
endif;
if(alarmnum<3)then
alarm<='0';
else
alarm<='1';
endif;
if(vers='1')then
vering<='1';
endif;
if(vering='1')then
if(ready='1')then
if(cd1=dt1andcd2=dt2andcd3=dt3andcd4=dt4andcd5=dt5andcd6=dt6)then
result<='1';
else
result<='0';
wronging<='1';
if(alarmnum<3)then
alarmnum<=alarmnum+1;
endif;
endif;
vering<='0';
endif;
endif;
elsif(clk'eventandclk='0')then
if(wronging='1')then
wrong<='1';
elsif(wronging='0')then
wrong<='0';
endif;
endif;
endprocess;
endver_behave;
★寄存模块:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitycodeis
port
(dt1,dt2,dt3,dt4,dt5,dt6:
instd_logic_vector(3downto0);
change:
instd_logic;
ready:
instd_logic;
ok:
instd_logic;
clk:
instd_logic;
result:
instd_logic;
reset:
instd_logic;
wt:
outstd_logic;
cd1,cd2,cd3,cd4,cd5,cd6:
outstd_logic_vector(3downto0)
);
endcode;
architecturecode_behaveofcodeis
signalalarmnum:
integerrange0to3;
signalchanging:
std_logic;
signalchanged:
std_logic;
signalwting:
std_logic;
begin
process(clk)
begin
if(clk'eventandclk='1')then
if(ok='1'andchanging='0'andresult='1')then
wting<='1';
else
wting<='0';
endif;
if(reset='1')then
cd1<="1001";
cd2<="1001";
cd3<="1001";
cd4<="1001";
cd5<="1001";
cd6<="1001";
endif;
if(change='1')then
changing<='1';
endif;
if(changing='1')then
if(ready='1')then
if(result='1')then
cd1<=dt1;
cd2<=dt2;
cd3<=dt3;
cd4<=dt4;
cd5<=dt5;
cd6<=dt6;
wting<='1';
endif;
changing<='0';
endif;
endif;
elsif(clk'eventandclk='0')then
if(wting='1')then
wt<='1';
else
wt<='0';
endif;
endif;
endprocess;
endcode_behave;
★计数及使能模块:
1
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitykeyboardis
port
(a3,a2,a1,a0:
instd_logic;
a:
outstd_logic_vector(3downto0);
k:
instd_logic;
keysign:
outstd_logic;
clk:
instd_logic
);
endkeyboard;
architecturekeyboard_behaveofkeyboardis
begin
process(clk)
begin
if(clk'eventandclk='0')then
a(3)<=a3;
a
(2)<=a2;
a
(1)<=a1;
a(0)<=a0;
keysign<=k;
endif;
endprocess;
endkeyboard_behave;
2
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitykeyinis
port
(en:
instd_logic;
clk:
instd_logic;
a:
instd_logic_vector(3downto0);
keysign:
instd_logic;
ok:
instd_logic;
cancel:
instd_logic;
ver:
instd_logic;
ready:
outstd_logic;
dt1,dt2,dt3,dt4,dt5,dt6:
outstd_logic_vector(3downto0)
);
endkeyin;
architecturekeyin_behaveofkeyinis
signalcount:
integerrange0to7;
signalcready:
std_logic;
begin
process(en,clk,keysign)
begin
if(en='1')then
if(clk'eventandclk='1')then
if(keysign='1'andcount<6)then
count<=count+1;
if(count=0)then
dt1<=a;
elsif(count=1)then
dt2<=a;
elsif(count=2)then
dt3<=a;
elsif(count=3)then
dt4<=a;
elsif(count=4)then
dt5<=a;
elsif(count=5)then
dt6<=a;
endif;
endif;
if(ver='1')then
count<=0;
endif;
if(cancel='1')then
count<=0;
dt1<="1111";
dt2<="1111";
dt3<="1111";
dt4<="1111";
dt5<="1111";
dt6<="1111";
endif;
if(ok='1')then
count<=0;
cready<='1';
else
cready<='0';
endif;
elsif(clk'eventandclk='0')then
if(cready='1')then
ready<='1';
else
ready<='0';
endif;
endif;
endif;
endprocess;
endkeyin_behave;‘
※各个模块与设计存在出入,但基本要求都达到,主要是小组分工时,没有能完全按照模块分块设计
※计数器模块分散开没有单独形成模块
※具体信号意义见仿真
Block图:
计数器
比较器
寄存器
控制器
五、仿真:
Reset:
重置(缺省)
A:
输入
k:
判断有效输入
OK:
确认
Cancel:
取消
Ver:
进入工作(比较)
Change:
修改密码
Clk:
时钟信号
Result:
开锁
En-out:
使能
Wrong:
报错
Alarm:
报警
Stopalarm:
停止操作(管理员使用)
1.验证缺省密码为999999(reset键);
2.验证输入错误取消输入,重新输入(cancel键);
3.验证60秒无操作自动返回等待界面(en-out和result归零);
4.验证有效按键“k”,只有k为高电平有效;
5.验证用户操作完成,再次按ok键,自动返回等待键;
6.验证输入密码错误发出提示信号,连续三次输入错误,发出报警信号,只有按下stopalarm才能停止。
7.验证只取前六位输入,其它无效
(再次验证无操作60自动返回等待)
六、小组分工:
组长李黎完成框架设计代码的编写,完成主要代码编写;
陈宗渊完成代码的编写与完善及block图的连接;
周炳宇完成代码的校错及仿真。
小组一起完成实验报告,每人约占1/3。
七、小结:
在短学期差不多一个月的时间里,我们经过自己的努力用VHDL编写了密码锁,学到了很多的知识,当然也总结了很多的经验和教训。
在程序编写的过程中,我们遇到很多困难,但是我们一点也没有放弃,坚持了下来,最终编写出了程序,完成基本的要求。
我们总结,要学会使用图书馆等网络资源,当我们编写程序遇到一些无法理解得错误时,我们最终都可以从书上找到前人的经验和教训。
因此我们认为不能闭门造车,要多学习别人的经验和教训。
在编写程序之前要有一个清晰的框架,自己要实现哪些功能,以及要实现哪些功能得需要哪些方法来实现,只有在自己脑子里有一个很清晰的框架之后,然后再进行编写,我们在编写开始时由于没有一个清晰的框架,导致在程序编写到一半是才发现有些功能我是需要重新增加很多变量和减少变量,这是我又得重新编写,一切从头开始,这在无形中加大了自己的工作量。
所以,不要急于忙的编写程序,自己要得先想好,家乡有句俗语叫,“低头拉车,抬头看天。
”,应该就是这个道理。
心态要好,不要急躁和急于求成。
编写一个健壮的程序是需要一定的时间去思考调试的,因此只有努力花时间,才能够编写一个我们满意的程序。
在完成设计的过程中,我们遇到诸如数据类型不对,算法错误,仿真波形不同步等问题,但在我们的努力下,都基本解决了这些问题,但是由于小组的能力有限,程序还有不够完善之处,比如模块设计没有完全按照设想的那样,显得有些紊乱,程序缺点在于不便维护,望老师批评指正。
枯藤老树昏鸦,小桥流水人家,古道西风瘦马。
夕阳西下,断肠人在天涯。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- vhdl 密码锁