📄 cornaa.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
entity cornaa is
port(clk,k1,k0,clr,load,lc:in std_logic; --k1,k0分别为代表1和0的按键开关
lt:inout std_logic; --load为设置密码的开关
lamp:out std_logic_vector(7 downto 0); --lamp接发光二极管,用来显示已经输入密码的个数
bcd1,bcd2:out std_logic_vector(3 downto 0);
lf,alm:out std_logic); --clr用来清楚报警信号和关锁
end cornaa;
architecture corn_arc of cornaa is
signal shift,lock:std_logic_vector(7 downto 0);
signal lam:std_logic_vector(7 downto 0);
signal la:std_logic;
begin
process(clk,lc)
begin
wait until clk='1';
if lc='0' then
lock<="10010101";
end if;
end process;
process(clk,clr)
begin
if clr='0' then
la<='0';
elsif clk'event and clk='1' then
if load='0' then
if lt='1' then
la<='1';
end if;
end if;
end if;
end process;
process(clk,clr)
variable a:integer range 0 to 8;
begin
if clr='0' then
lam<="00000000";
shift<="00000000";
a:=0;
lt<='0';
lf<='0';
alm<='0';
elsif clk'event and clk='1' then
if lt='0' then
if a/=8 then
if k1='0' then
shift<=shift(6 downto 0)&'1'; --输入一位密码“1”
lam<=lam(6 downto 0)&'1'; --显示输入了一个密码
bcd1<=shift(7 downto 4);
bcd2<=shift(3 downto 0);
a:=a+1;
elsif k0='0' then
shift<=shift(6 downto 0)&'0';
lam<=lam(6 downto 0)&'1';
bcd1<=shift(7 downto 4);
bcd2<=shift(3 downto 0);
a:=a+1;
end if;
else
a:=0;
if shift=lock then --密码正确
lt<='1';
else --密码错误
lf<='1';
alm<='1';
end if;
end if;
elsif la='1' then
if k1='0' then
lock<=lock(6 downto 0)&'1'; --设置一位密码"1"
lam<=lam(6 downto 0)&'0'; --显示设置了一位密码
elsif k0='0' then
lock<=lock(6 downto 0)&'0'; --设置一位密码“0”
lam<=lam(6 downto 0)&'0';
end if;
end if;
end if;
end process;
lamp<=lam;
end corn_arc;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -