毕 业 论 文 ﹙设 计﹚ 开 题 报 告
题 目 基于VHDL的密码锁设计 学生姓名 学号
所在院(系) 电 信 工 程 系 专业班级 通 信
指导教师
2010 年 4 月 6 日
1
2
3
4
第二篇:VHDL电子密码锁
设计一个6位并行(或串行)电子密码锁,要求当输入的密码与锁内的密码一致时,,绿灯亮,开锁;当输入的密码与锁内的密码不一致时,红灯亮,不能开锁。密码可由用户自行设置。
设计要求:
1分析设计任务,拟定多种设计方案,根据实验条件,选定其中一种方案绘制系统框图和设计流程。
2设计相关电路并编写VHDL程序。
3对设计电路进行功能仿真,分析仿真波形。
4对设计电路要进行编程下载,记录结果。
5撰写设计报告一份。
设计方案
(1)采用文本输入法,用一个源程序控制整个电路,然后利用顶层文件将它们综合起来,最终使其具有电子密码锁的功能。
(2)采用文本和原理图两种方法设计,密码锁的主体部分(包括密码设置、密码修改、密码检测、开锁电路、执行电路等部分。)用文本设计法完成,当主体部分完成后,将其打包后,再用原理图输入法使各个部分综合起来。
由以上两种方案分析,方案(1)全部采用文本输入法,在顶层设计中比较杂,一旦出现错误,将不易更改,程序调试耗时会比较长。方案(2)采用了文本和原理图两种方法进行设计,主体部分完成后,再用另一种方法设计译码部分,最后两部分综合,调试起来会比较方便。
综合以上原因,从实现难易,误差大小以及最终结果等各方面考虑,选择方案(2)来完成该实验。根据方案(2)中密码锁的实现原理,本次设计方案 可分为三个模块来实现其功能,即消抖电路、消抖同步电路、核心电路几个单元,在核心电路中又包括密码设置电路、密码输入电路、密码锁控制电路和密码锁显示电路四部分组成。控制部分还需包含密码修改、密码检测、开锁电路、执行电路等部分。
分别用VHDL对其进行编程,实现消抖电路、消抖同步电路、核心电路等。 然后对其打包后,利用原理图输入法使各个部分综合起来。
系统结构
消除抖动模块
Library ieee; Use ieee.std_logic_1164.all; Entity fen is
Port(clk:in std_logic;
Cp :out std_logic);
End fen;
Architecture fen_arc of fen is
Begin
Process(clk)
Variable cnt:integer range 0 to 999; Begin
If clk'event and clk='1'then
If cnt=9 then
Cnt:=0;
Cp<='1';
Else
Cnt:=cnt+1;
Cp<='0';
End if;
End if;
End process;
End fen_arc;
消抖同步模块
library ieee;
use ieee.std_logic_1164.all; entity xiaopro is
port(a,clk2:in std_logic;
b:out std_logic);
end xiaopro;
architecture xiao_arc of xiaopro is signal tmp1:std_logic;
begin
process(clk2,a)
variable tmp3,tmp2:std_logic; begin
if clk2'event and clk2='0'then tmp1<=a;
tmp2:=tmp1;
tmp3:=not tmp2;
end if;
b<=tmp1 and tmp3 and clk2; end process;
end xiao_arc;
逻辑功能模块
Library ieee;
Use ieee.std_logic_1164.all; Entity cornaa2 is
Port(clk,k1,k0,clr,load:in std_logic; lt:inout std_logic;
lamp:out std_logic_vector(5 downto 0); lf,alm:out std_logic);
end cornaa2;
architecture corn_arc of cornaa2 is
signal shift,lock:std_logic_vector(5 downto 0); signal lam:std_logic_vector(5 downto 0); signal la:std_logic;
begin
process(clk,clr)
begin
If clr='0'then
la<='0';
elsif clk'event and clk='1' then
if load='0' then
la<='1';
end if;
end if;
end process;
process(clk,clr)
variable a:integer range 0 to 6; begin
If clr='0' then
lam<="111111";
Shift<="000000";
a:=0;
lt<='1';
lf<='1';
alm<='0';
Elsif clk'event and clk='1'then
if la='1' then
if k1='0'then
lock<='1'&lock(5 downto 1); lam<='0'&lam(5 downto 1); elsif k0='0'then
lock<='0'&lock(5 downto 1); Lam<='0'&lam(5 downto 1); end if;
elsif lt='1' then
if a/=6 then
if k1='0' then
Shift<='1'&shift(5 downto 1); lam<='0'&lam(5 downto 1); a:=a+1;
elsif k0='0' then
Shift<='0'&shift(5 downto 1); lam<='0'&lam(5 downto 1); a:=a+1;
end if;
else
a:=0;
if shift=lock then
lt<='0';
else
lf<='0';
alm<='1';
end if;
end if;
end if;
end if;
end process;
lamp<=lam;
end corn_arc;
密码锁的原理图