打印

VHDL课程设计:四位电子密码锁(附答辩PPT)

[复制链接]
497|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 远程烧录联盟 于 2020-12-15 16:59 编辑

VHDL课程设计:四位电子密码锁

荒废了一个假期,快要开学了,写篇博客"庆祝庆祝",同时,今天心情也不是很好,算了,废话不多说,下面进入正题吧。

1.题目要求:

本次博客的题目是利用VHDL设计一个四位密码锁,题目要求如下:

四位密码,使用数据开关K1-K10分别代表数字0-9

输入密码用数码管显示,每输入一位,密码左移一位

删除的是最后一位数字,删除一位,右移一位,空出位补充”0”

用一位输出电平表示锁开闭状态

设置万能密码,在忘记密码的情况下可以打开锁

2.源码及注释(文件附件下载):

编译的软件为Quartus II13.0,工程如何建立大家应该都知道了,这块不多讲,就直接添加各个模块相关源码及注释 PS:实在不想排版了,附件有源码文件加载,需要用的直接下载就行。

顶层文件:fanzhen.vhd

--顶层文件。
LIBRARYieee;
USEieee.std_logic_1164.all;
LIBRARYwork;
--实体描述
ENTITYfangzhenIS
port(
rest:INSTD_LOGIC;
shizhongxinhao:INSTD_LOGIC;
gaimij:INSTD_LOGIC;
querenj:INSTD_LOGIC;
shanchuj:INSTD_LOGIC;
jianpanshurru:INSTD_LOGIC_VECTOR(3downto0);
zhenque_gaodianping:OUTSTD_LOGIC;
baojing:OUTSTD_LOGIC;
zhishideng:OUTSTD_LOGIC;
qimaguanxianshi:OUTSTD_LOGIC_VECTOR(15downto0));
ENDfangzhen;
--结构体描述
ARCHITECTUREbdf_typeOFfangzhenIS
--验证改密元件定义
componentyzgm
PORT(
clk:INSTD_LOGIC;
gaimij2:INSTD_LOGIC;
queren:INSTD_LOGIC;
input2:INSTD_LOGIC_VECTOR(15downto0);
output2:OUTSTD_LOGIC);
endcomponent;
--移位寄存器元件定义
componentywjcq
PORT(
rest:INSTD_LOGIC;
shanchu:INSTD_LOGIC;
clk:INSTD_LOGIC;
input:INSTD_LOGIC_VECTOR(3downto0);
output:OUTSTD_LOGIC_VECTOR(15downto0));
endcomponent;
--数码管显示元件定义
componentyimasc
PORT(
clk:INSTD_LOGIC;
datain:INSTD_LOGIC_VECTOR(15downto0);
dataout:OUTSTD_LOGIC_VECTOR(15downto0));
endcomponent;
--电锁控制元件定义
componentdskz
PORT(
clk:INSTD_LOGIC;
input:INSTD_LOGIC;
reset:INSTD_LOGIC;
queren:INSTD_LOGIC;
light:OUTSTD_LOGIC;
alarm:OUTSTD_LOGIC);
endcomponent;
--d4触发器元件定义
componentd4
port(
clk:instd_logic;
a:instd_logic_vector(3downto0);
rest1,querenj1,gaimij1,shanchuj1:instd_logic;
q:outstd_logic_vector(3downto0);
rest2,querenj2,gaimij2,shanchuj2:outstd_logic;
oclk:outstd_logic);
endcomponent;
--输入密码存放
signalSYNTHESIZED_WIRE_0:STD_LOGIC_VECTOR(15downto0);
--开锁信号
signalSYNTHESIZED_WIRE_1:STD_LOGIC:='0';
--按键
signalkey:std_LOGIC_VECTOR(3downto0);
--依次是重置、确认、改密、删除、以及键盘输入信号
signalrest3,querenj3,gaimij3,shanchuj3,ok:STD_LOGIC;
BEGIN
zhenque_gaodianping<=SYNTHESIZED_WIRE_1;
--验证改密元件例化
b2v_inst:yzgm
PORTMAP(clk=>shizhongxinhao,
gaimij2=>gaimij3,
queren=>querenj3,
input2=>SYNTHESIZED_WIRE_0,
output2=>SYNTHESIZED_WIRE_1);
--移位寄存器元件例化
b2v_inst1:ywjcq
PORTMAP(rest=>rest3,
shanchu=>shanchuj3,
clk=>ok,
input=>key,
output=>SYNTHESIZED_WIRE_0);
--数码管显示元件例化
b2v_inst2:yimasc
PORTMAP(
clk=>shizhongxinhao,
datain=>SYNTHESIZED_WIRE_0,
dataout=>qimaguanxianshi);
--电锁控制元件例化
b2v_inst3:dskz
PORTMAP(clk=>shizhongxinhao,
input=>SYNTHESIZED_WIRE_1,
reset=>rest3,
queren=>querenj3,
light=>zhishideng,
alarm=>baojing
);
--d4触发器例化
b2v_inst4:d4
portmap(
clk=>shizhongxinhao,
a=>jianpanshurru,
rest1=>rest,
querenj1=>querenj,
gaimij1=>gaimij,
shanchuj1=>shanchuj,
q=>key,
rest2=>rest3,
querenj2=>querenj3,
gaimij2=>gaimij3,
shanchuj2=>shanchuj3,
oclk=>ok);
END;

D4触发器:d4.vhd

--D触发器:实现消抖作用
libraryieee;
useieee.std_logic_1164.all;
--d4触发器实体描述
entityd4is
port(
clk:instd_logic;
a:instd_logic_vector(3downto0);
rest1,querenj1,gaimij1,shanchuj1:instd_logic;
q:outstd_logic_vector(3downto0);
rest2,querenj2,gaimij2,shanchuj2:outstd_logic;
--表示按键按下信号以及删除键按下信号
oclk:outstd_logic);
endd4;
--d4结构体描述
architecturefofd4is
signalqi:integerrange0to200;
signalclk_temp,delay:std_logic;
begin
process(clk)
begin
ifrising_edge(clk)then
ifqi=200then
qi<=0;
clk_temp<='1';
else
qi<=qi+1;
clk_temp<='0';
endif;
endif;
endprocess;
process(clk_temp)
begin
ifclk_temp'eventandclk_temp='1'then
ifa/="0000"then
q<=a;
oclk<='1';
elsifshanchuj1/='0'then
shanchuj2<='1';
oclk<='1';
else
shanchuj2<='0';
oclk<='0';
endif;
rest2<=rest1;querenj2<=querenj1;
gaimij2<=gaimij1;
endif;
endprocess;
endif;

数码管显示模块:yimasc.vhd

--数码管显示部分代码
libraryieee;
useieee.std_logic_1164.all;
--实体描述
entityyimascis
port(
--显示数据
datain:instd_logic_vector(15downto0);
clk:instd_logic;
--数码管输出
dataout:outstd_logic_vector(15downto0));
endyimasc;
--结构体描述
architecturebehaveofyimascis
begin
process(clk)
begin
ifclk'eventandclk='1'then
dataout<=datain;
endif;
endprocess;
endbehave;

移位寄存器模块:ywjcq.vhd

--移位寄存器,用于保存四位密码、删除密码控制
libraryieee;
useieee.std_logic_1164.all;
--实体描述
entityywjcqis
port(
--按键输入(一位)
input:instd_logic_vector(3downto0);
--重新输入,删除,输入脉冲
rest,shanchu,clk:instd_logic;
--密码输出
output:outstd_logic_vector(15downto0));
endywjcq;
--结构体描述
architecturebehaveofywjcqis
begin
process(clk,shanchu)
variableoutput_tmp:std_logic_vector(15downto0):="1111111111111111";
variableok:std_logic:='0';
begin
ifrest='1'then
output_temp:="1110111011101110";
elsif(rising_edge(clk))then
ifshanchu='0'then
output_temp(15downto12):=output_temp(11downto8);
output_temp(11downto8):=output_temp(7downto4);
output_temp(7downto4):=output_temp(3downto0);
output_temp(3downto0):=input;
else
output_temp(3downto0):=output_temp(7downto4);
output_temp(7downto4):=output_temp(11downto8);
output_temp(11downto8):=output_temp(15downto12);
output_temp(15downto12):="1110";
endif;
endif;
output<=output_temp;
endprocess;
endbehave;

验证改密模块:yzgm.vhd

--验证改密模,验证密码以及改密
libraryieee;
useieee.std_logic_1164.all;
--模块试题描述
entityyzgmis
port(
--时钟信号,改密键,确认键
clk,gaimij2,queren:instd_logic;
--输入密码
input2:instd_logic_vector(15downto0);
--锁信号,1:表示验证通过0:表示验证未通过
output2:outstd_logic);
endyzgm;
--结构体描述
architectureaofyzgmis
begin
process(clk,gaimij2)
--设置初始密码是:8421
variableinput2_temp:std_logic_vector(15downto0):="1000010000100001";
--万能密码为:8888
variableinput2_temp1:std_logic_vector(15downto0):="1000100010001000";
begin
ifclk'eventandclk='1'then
--改密
ifgaimij2='1'then
input2_temp:=input2;
endif;
--验证
ifqueren='1'then
ifinput2_temp=input2orinput2=input2_temp1then
output2<='1';
else
output2<='0';
endif;
endif;
endif;
endprocess;
enda;

以上就是工程需要建立的相关文件,工程建立以后,就直接编译,然后配置好引脚烧录就行。

3.答辩讲解PPT(

点击下载PPT

):

像这种课程设计类的答辩基本就是这种模式,首先讲题目要求,然后方案,接下来就是源码讲解,最后就是试验中遇到的问题以及随便写一些心得体会就行。

部分PPT截图:
















附件:

http://down.51cto.com/data/2366453

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

38

主题

42

帖子

0

粉丝