小白萌新,思路仅供参考,问题较多,有待改善
- 设计要求
4个按键为密码输入键,可以用另一个按键作为复位,当按下复位按键时可以重新开始输入新的密码。利用一位数码管显示输入密码的次数,另一位显示正确与否,如果正确数码管显示“H”,如果错误,数码管显示“E”.当超过3次时如果密码仍然输入不正确 - 程序
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_misc.all;
-- **************************************
entity Lock is
generic
(
mima:std_logic_vector(7 downto 0):="11011001" --默认密码
);
port
(
clk:in std_logic; --时钟
key:in std_logic_vector(3 downto 0); --按键输入
reset: in std_logic; --按键复位
beep:out std_logic; --蜂鸣器
tf:out std_logic_vector(6 downto 0); --正确错误信息
num:out std_logic_vector(6 downto 0) --次数
);
end Lock;
-- **************************************
architecture behv of Lock is
type state is(st0,st1,st2,st3,st4,st5,ss0,ss1,ss2,ss3); --状态1
signal current_state,next_state:state:=st0; --当前状态,下一状态
signal secret_temp:std_logic_vector(7 downto 0):="00000000";
signal tf_cnt:integer range 0 to 7:=0; --错误计数
signal beep_cnt:integer range 0 to 7:=0 ; --错误计数
signal key_temp:std_logic;--按键释放
begin
COM1:process(clk) --时钟
begin
if clk'event and clk='1' then
current_state<=next_state;
end if;
end process COM1;
-- **************************************
COM2:<