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

📄 cornaa.vhd

📁 数字锁的功能:设置一个8位密码
💻 VHD
字号:
library ieee;              
use ieee.std_logic_1164.all;   
entity cornaa is												  -----LOAD 为设置密码的开关
	port(clk,k1,k0,clr,load:in std_logic;						-----K1,K0 分别是代表1和0的按键开关
	lt:inout std_logic;											-----CLR用来清除报警信号和关锁
	lamp:out std_logic_vector(7 downto 0);							------LAMP接发光二极管,用来显示已经输入密码的个数
	lf,alm:out std_logic);
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,clr)
	begin
		if clr='0' then
			la<='0';
		elsif clk'event and clk='1' then
			if load ='0' then
				la<='1';
			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<='1' & shift (7 downto 1);   ------输入一位密码“1”
						lam<='1' & lam (7 downto 1);		------显示输入了一位密码
						a:=a+1;
					elsif k0='0' then
						shift<='0' & shift (7 downto 1);	-----输入一位密码“0”
						lam<='1' & lam (7 downto 1);		
						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<='1' & lock(7 downto 1);		------设置一位密码为“1”
					lam<='0' & lam(7 downto 1);		------显示设置了一位密码
				elsif k0='0' then
					lock<='0' & lock(7 downto 1);		------设置了一位密码为“0”
					lam<='0' & lam(7 downto 1);
				end if;
			end if;
		end if;
	end process;
	lamp<=lam;
end corn_arc;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -