📄 mima.vhd
字号:
--文件名:mima.vhd
--功 能:7位密码锁
--说 明:输入密码为七位二进制数,三次错误后报警;当P1处于被拨下来时(高电平)
-- 进入用户设置密码状态,否则进行密码输入比较,密码正确D4亮,错误D3亮;
-- 三次输入密码错误则报警
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity mima is
Port ( clk : in std_logic ;
q : in std_logic_vector(6 downto 0); --输入的密码,接拨盘开关;
cs : out std_logic; --选通发光二极管的锁存信号;
enter : in std_logic; --数据输入后的确定键,接S6;
p1 : in std_logic; --设置、运行开关,接拨盘开关的第一个;
p2 : in std_logic; --直接开密码锁, 接S3按键;
p3 : in std_logic; --开锁 ,接S4按键;
led1: out std_logic; --密码错误亮灯(D3);
led2 : out std_logic; --密码正确 (D4);
led3,led4,led5,led6,led7,led8 : out std_logic;
bj : out std_logic); --报警器
end mima;
architecture Behavioral of mima is
signal clk1,a,clk2 : std_logic;
signal q1,q2 : std_logic_vector(6 downto 0);
begin
process(clk)
variable cnt : integer range 0 to 50000;
begin
if clk'event and clk='1' then cnt:=cnt+1;
if cnt<25000 then clk1<='1';
elsif cnt<50000 then clk1<='0';
else cnt:=0;clk1<='0';
end if;
end if;
end process;
process(clk)
variable cnt0 : integer range 0 to 16000000;
begin
if clk'event and clk='1' then cnt0:=cnt0+1;
if cnt0<8000000 then clk2<='1';
elsif cnt0<16000000 then clk2<='0';
else cnt0:=0;clk2<='0';
end if;
end if;
end process;
process(p1,q)
begin
if clk'event and clk='1'then
if p1='1'then
if enter='0'then q1<=q;
end if;
else q2<=q;
end if;
end if;
end process;
process(p2,p3)
variable cnt1 : integer range 3 downto 0;
begin
cs<='1';
if clk2'event and clk2='1'then led1<='1';led2<='1';
if p2='0'then led1<='1';led2<='0'; led3<='1';led4<='1';led5<='1';led6<='1';led7<='1';led8<='1';
elsif p3='0'then
if q1=q2 then led1<='1';led2<='0';led3<='1';led4<='1';led5<='1';led6<='1';led7<='1';led8<='1';a<='0';
elsif q1/=q2 then led2<='1';led1<='0';cnt1:=cnt1+1;led3<='1';led4<='1';led5<='1';led6<='1';led7<='1';led8<='1';
if cnt1=3 then led1<='0';a<='1';led2<='1'; led3<='1';led4<='1';led5<='1';led6<='1';led7<='1';led8<='1';
end if;
end if;
end if;
end if;
end process;
process(p3)
begin
if p3='1'then bj<='1';
elsif a<='1'then
bj<=clk1;
if a<='0'then bj<='1';
end if;
end if;
end process;
end Behavioral;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -