⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mms.vhd

📁 基础性试验 实践性试验 综合性试验 提升性试验 交通灯设计
💻 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 + -