?? mms.vhd
字號:
library IEEE;
--文件名:mms.vhd
--功 能:4位密碼鎖
--說 明:輸入4位十六進制密碼,如果三次錯誤的話就報警 ;
-- 密碼是四位一下四位一下的輸入,處于密碼設置狀態,又P3被按下時實現輸入密碼存儲位的增加;
-- 密碼設置之后,按S7,密碼被設置到系統中;然后在P1處于開鎖狀態時,進行新密碼的輸入,并
-- 進行三次比較,有錯,D3亮;并報警;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity mms is
Port ( clk : in std_logic;
p1 : in std_logic; --設置、運行開關,撥盤開關的第三個;
clr : in std_logic; --清除開關,第一個撥盤開關;
p2 : in std_logic; --直接開密碼鎖,接S4;
enter : in std_logic; -- 接S7;
p4 : in std_logic; --開鎖 ,接S6;
p3 : in std_logic; --輸入位選擇 ,接S3;
sz : in std_logic_vector(3 downto 0); --四位輸入
bj : out std_logic; --三次錯誤報警
cs : out std_logic;
led1 : out std_logic; --密碼錯誤亮燈(D3)
led3,led4,led5,led6,led7,led8 : out std_logic;
led2 : out std_logic); --密碼正確(D4)
end mms;
architecture Behavioral of mms is
signal a1 : std_logic_vector(15 downto 0);
signal a2 : std_logic_vector(15 downto 0);
signal a3,clk1,clk2 : std_logic;
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 20000000;
begin
if clk'event and clk='1' then cnt0:=cnt0+1;
if cnt0<10000000 then clk2<='1';
elsif cnt0<20000000 then clk2<='0';
else cnt0:=0;clk2<='0';
end if;
end if;
end process;
process(p1,p3,clr) --設置密碼進程
variable cnt1 : integer range 0 to 16;
begin
if clk2'event and clk2='1'then
if clr='0'then a1<="0000000000000000";
elsif p1='1'then
if p3='0'then cnt1:=cnt1+4;
end if;
if enter='0'then
if cnt1=4 then a1(15 downto 12)<=sz;
elsif cnt1=8 then a1(11 downto 8)<=sz;
elsif cnt1=12 then a1(7 downto 4)<=sz;
elsif cnt1=16 then a1(3 downto 0)<=sz;
end if;
end if;
end if;
end if;
end process;
process(p1,p3,clr) --輸入密碼進程
variable cnt2 : integer range 0 to 16;
begin
if clk2'event and clk2='1'then
if clr='0'then a2<="0000000000000000";
elsif p1='0'then
if p3='0' then cnt2:=cnt2+4;
end if;
if enter='0'then
if cnt2<=4 then a2(15 downto 12)<=sz;
elsif cnt2<=8 then a2(11 downto 8)<=sz;
elsif cnt2<=12 then a2(7 downto 4)<=sz;
elsif cnt2<=16 then a2(3 downto 0)<=sz;
end if;
end if;
end if;
end if;
end process;
process (a1,a2,p2) --設置密碼和輸入密碼的比較以及管理員單鍵開鎖
variable cnt3 : integer range 0 to 3;
begin
cs<='1';
if clk2'event and clk2='1'then led1<='1';led2<='1'; a3<='0';
if p2='0'then led2<='0'; led3<='1';led4<='1';led5<='1';led6<='1';led7<='1';led8<='1';
elsif p4='0'then
if a1=a2 then led2<='0';led3<='1';led4<='1';led5<='1';led6<='1';led7<='1';led8<='1';
elsif a1/=a2 then led2<='1';led1<='0';cnt3:=cnt3+1;led3<='1';led4<='1';led5<='1';led6<='1';led7<='1';led8<='1';
if cnt3=3 then led1<='0';a3<='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 (p2)
begin
if p2='0' then
bj<='1';
elsif a3='1'then
bj<=clk1;
if a3='0'then bj<='1';
end if;
end if;
end process;
end Behavioral;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -