?? 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 + -