VHDL课程设计数字密码锁电路.docx
《VHDL课程设计数字密码锁电路.docx》由会员分享,可在线阅读,更多相关《VHDL课程设计数字密码锁电路.docx(12页珍藏版)》请在冰豆网上搜索。
![VHDL课程设计数字密码锁电路.docx](https://file1.bdocx.com/fileroot1/2022-10/26/e3ab8f63-07f9-4028-ab33-1a7fc58027f6/e3ab8f63-07f9-4028-ab33-1a7fc58027f61.gif)
VHDL课程设计数字密码锁电路
VHDL课程设计——
数字密码锁
班级:
计052—2班
学号:
200525502204
姓名:
杨彦涛
指导老师:
沈春华
日期:
2007-1
一、设计要求
设计一个简易的数字密码锁,该锁应在收到3位与规定码相符的十进制数码时打开,使相应的指示灯点亮;若收到的代码与规定的不符或者开锁程序有误,表示错误的只是灯点亮。
二、系统功能描述
1、系统接通电源后,首先按动setup键后方投入运行。
运行时标志开门的指示灯和报警灯、铃皆不工作,系统处于安锁状态。
2、开锁代码是3位十进制数,可以通过系统预先设定。
开锁时输入代码不足三位或超过三位均不能开锁。
3、开锁程序由设计者确定,用户必须严格执行所规定的程序,方可开锁。
4、开锁代码和程序正确,表示数字锁打开的指示灯亮。
5、允许用户在开锁过程中有1次错误(输入代码错误或开锁程序错误),只要出错,表示错误的指示灯必定点亮。
如果有2次错误,则报警器——喇叭名叫,以示情况异常。
6、开锁程序为:
(1)按启动键(start)启动开锁程序,此时系统内部分处于初始状态。
(2)依次键入十进制码。
(3)按开门键(open)准备开门。
若按上述程序执行且拨号正确,则开门继电器工作,lock=1;若密码输入错误或未按上述程序执行,则按动开门键(open)后报警灯亮,红灯亮。
(4)开锁事务处理完毕后,应将门关上,按set键,使系统重新进入安锁状态。
(若在报警,按set或start均不起作用,应另用一内部的I_setup键才能使系统进入安锁状态)。
(5)若按错号码,可在按confirm键之前按start键重新启动开锁程序。
7、号码0-9,start,open,setcode,confirm均用按键产生。
8、alarm表示警报,red表示红灯,lock表示开锁信号。
三、密码锁控制器的MDS图及其功能说明。
当系统处于s0状态时,为安锁状态按start进入开锁程序s2,输入代码确定,按open进入s2状态,如果输入正确,进入s3状态并输出gree=1;.此时按setup可以重新进入安锁状态。
如果输入有误则进入s4状态并输出red=1.此时按setup可以重新进入安锁状态。
再按start启动开锁程序,输入代码并确定,按open进入s3状态,,如果输入正确,进入s4状态并输出gree=1;.此时按setup可以重新进入安锁状态。
如果输入有误则进入s5状态并输出red=1,jbao=1;.此时按i_setup可以重新进入安锁状态。
四,顶层电路结构图及源代码
1.元件例化后程序图30
i_setup
setup
start
open1
result
clk512
clk
en
gree
red
jbao
kaimen
KONGZHI
i_setup
setup
start
open1
result
clk512
clk
en
gree
red
jbao
kaimen
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
entityelockis
port(clk,i_setup,setup,setcode,start,confirm,olock,
s0,s1,s2,s3,s4,s5,s6,s7,s8,s9:
instd_logic;
alarm:
bufferstd_logic;
lock:
outstd_logic;
red:
outstd_logic);
endelock;
architectureoneofelockis
componentcontr
port(clk:
instd_logic;
i_setup:
instd_logic;
setup:
instd_logic;
start:
instd_logic;
olock:
instd_logic;
result:
instd_logic;
alarm:
bufferstd_logic;
lock:
outstd_logic;
red:
outstd_logic);
endcomponent;
componentwrite
port(cp,reset:
instd_logic;
start,setcode,confirm:
instd_logic;
s0:
instd_logic;
s1:
instd_logic;
s2:
instd_logic;
s3:
instd_logic;
s4:
instd_logic;
s5:
instd_logic;
s6:
instd_logic;
s7:
instd_logic;
s8:
instd_logic;
s9:
instd_logic;
co:
outstd_logic;
co1,co2,co3:
outstd_logic_vector(0to3);
m1,m2,m3:
outstd_logic_vector(0to3)
);
endcomponent;
componentcompare
port(co,con,reset:
instd_logic;
s1,s2,s3:
instd_logic_vector(0to3);
c1,c2,c3:
instd_logic_vector(0to3);
result:
outstd_logic);
endcomponent;
signalco,re:
std_logic;
signaln1,n2,n3:
std_logic_vector(0to3);
signalc1,c2,c3:
std_logic_vector(0to3);
begin
u1:
contrportmap(clk,i_setup,setup,start,olock,re,alarm,lock,red);
u2:
writeportmap(clk,setup,start,setcode,confirm,
s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,co,n1,n2,n3,c1,c2,c3);
u3:
compareportmap(co,olock,setup,n1,n2,n3,c1,c2,c3,re);
endone;
2.用gdf图连接
四、主要功能模块设计说明及源程序。
1.控制器
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitymmtrolis
port(i_setup,setup,start,open1,result,clk512,clk:
instd_logic;
en,gree,red,jbao,kaimen:
outstd_logic);
endmmtrol;
architecturemmtrol1ofmmtrolis
typestatsis(s0,s1,s2,s3,s4,s5,s6);
signalcurrent_state,next_state:
stats;
begin
reg:
process(clk)
begin
if(clk'eventandclk='1')then
current_state<=next_state;
endif;
endprocess;
com:
process(current_state,result,open1,setup,start,i_setup)
begin
casecurrent_stateis
whens0=>en<='0';gree<='0';red<='0';jbao<='0';kaimen<='0';
ifstart='1'thennext_state<=s1;
elsifopen1='1'andstart='0'thennext_state<=s4;
elsenext_state<=s0;
endif;
whens1=>en<='1';gree<='0';red<='0';jbao<='0';kaimen<='0';
ifsetup='1'thennext_state<=s0;
elsifresult='0'thennext_state<=s6;
elsifresult='1'thennext_state<=s2;
elsenext_state<=s1;
endif;
whens2=>en<='1';gree<='0';red<='0';jbao<='0';kaimen<='0';
ifsetup='1'thennext_state<=s0;
elsifopen1='1'thennext_state<=s3;
elsenext_state<=s2;
endif;
whens3=>en<='1';gree<='1';red<='0';jbao<='0';kaimen<='1';
ifsetup='1'thennext_state<=s0;
elsenext_state<=s3;
endif;
whens6=>en<='1';gree<='0';red<='0';jbao<='0';kaimen<='0';
ifsetup='1'thennext_state<=s0;
elsifstart='1'thennext_state<=s1;
elsifopen1='1'thennext_state<=s4;
elsenext_state<=s6;
endif;
whens4=>en<='1';gree<='0';red<='1';jbao<='0';kaimen<='0';
ifsetup='1'thennext_state<=s0;
elsifresult='0'andopen1='1'thennext_state<=s5;
elsifresult='1'thennext_state<=s2;
elsenext_state<=s4;
endif;
whens5=>en<='1';gree<='0';red<='1';kaimen<='0';
jbao<=clk512;
ifi_setup='1'thennext_state<=s0;
elsenext_state<=s5;
endif;
endcase;
endprocess;
endmmtrol1;
2.编码器
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitybmqis
port(en,s0,s1,s2,s3,s4,s5,s6,s7,s8,s9:
instd_logic;
sor:
outstd_logic;
d0:
outstd_logic_vector(3downto0));
end;
architecturebmqxofbmqis
si