vhdl密码锁
- 格式:doc
- 大小:674.50 KB
- 文档页数:17
port
(dt1,dt2,dt3,dt4,dt5,dt6: in std_logic_vector(3 downto 0);
cd1,cd2,cd3,cd4,cd5,cd6: in std_logic_vector(3 downto 0);
vers: in std_logic;
if (en='0') then
result<='0';
end if;
if (stopalarm='1') then
alarmnum<=0;
end if;
if (wronging='1') then
wronging<='0';
vering<='1';
end if;
if (alarmnum<3) then
if (wronging='1') then
wrong<='1';
elsif (wronging='0') then
wrong<='0';
end if;
end if;
end process;
end ver_behave;
★寄存模块:
library ieee;
use ieee.std_logic_1164.all;
enable<='0';
sec<=0;
end if;
else
sec<=0;
end if;
end if;
end process;
end ctrl_behave;
★比较模块:
library ieee;
use ieee.std_logic_1164.all;
use iLeabharlann ee.std_logic_unsigned.all;
ready: in std_logic;
clk: in std_logic;
stopalarm: in std_logic;
en: in std_logic;
result: out std_logic;
wrong: out std_logic;
alarm: out std_logic
);
end ver;
architecture ctrl_behave of ctrl is
signal sec : integer range 0 to 60;
begin
process(clk)
begin
if (clk'event and clk='1') then
if (vers='1') then
enable<='1';
三、设计流程:
1.结构框图:
①按键输入;
②复位(设置缺省密码);
③等待状态
④工作状态
⑤修改密码
⑥提醒错误及报警
⑦开锁
⑧恢复等待
2.模块设计:
★控制模块:实现输入输出,实现等待工作的转换,实现开锁及报警;
★比较模块:比较输入密码与正确密码
★寄存模块:存放密码
★计数及使能模块:(1)输入个数为6,多于无效自动忽略;
(2)60s的空闲时间,无操作返回等待;
(3)错误次数为3
(4)进入工作状态,是能段即打开,直到进入等待。
四、具体实现:
★控制模块:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ctrl is
use ieee.std_logic_unsigned.all;
entity code is
endif;
if (wt='1' and result='1') then
enable<='0';
sec<=0;
end if;
if (change='0' and vers='0' and keysign='0' and ok='0' and cancel='0') then
sec<=sec+1;
if (sec=59) then
Vhdl短学期实验——密码锁设计
小组成员:
04008230 李黎
04008228 陈宗渊
04008211 周炳宇
一、课题描述:
用于模仿密码锁的工作过程。完成密码锁的核心控制功能。
二、功能要求:
设计一个密码锁,平时处于等待状态。管理员可以设置或更该密码。如果不预置密码,密码缺省为“999999”。用户如果需要开锁,按相应的按键进入输入密码状态,输入6位密码,按下确定键后,若密码正确,锁打开,若密码错误,将提示密码错误,要求重新输入,三次输入都错误,将发出报警信号。报警后,只有管理员作相应的处理才能停止报警。用户输入密码时,若输入错误,在按下确定键之前,可以通过按取消键重新输入。正确开锁后,用户处理完毕后,按下确定键,系统回到等待状态。系统操作过程中,只要密码锁没有打开,如果60秒没有对系统操作,系统回到等待状态。注意:输入按键信号时必须一个按键一个按键输入,不得6个按键一起输入。
port
(change,vers,keysign: in std_logic;
ok,cancel: in std_logic;
clk: in std_logic;
result: in std_logic;
wt: in std_logic;
enable: out std_logic
);
end ctrl;
architecture ver_behave of ver is
signal alarmnum : integer range 0 to 3;
signal vering : std_logic;
signal wronging: std_logic;
begin
process(clk)
begin
if (clk'event and clk='1') then
result<='1';
else
result<='0';
wronging<='1';
if (alarmnum<3) then
alarmnum<=alarmnum+1;
end if;
end if;
vering<='0';
end if;
end if;
elsif (clk'event and clk='0') then
alarm<='0';
else
alarm<='1';
end if;
if (vers='1') then
vering<='1';
end if;
if (vering='1') then
if (ready='1') then
if (cd1=dt1 and cd2=dt2 and cd3=dt3 and cd4=dt4 and cd5=dt5 and cd6=dt6) then