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

📄 lift.vhd

📁 不同于网上的四层电梯
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity lift is
 port(	buttonclk:in std_logic;
		liftclk:in std_logic;
		--clk:in std_logic;
		reset:in std_logic;
		f1upbutton:in std_logic;
		f2upbutton:in std_logic;
		f2dnbutton:in std_logic;
		f3upbutton:in std_logic;
		f3dnbutton:in std_logic;
		f4upbutton:in std_logic;
		f4dnbutton:in std_logic;
		f5upbutton:in std_logic;
		f5dnbutton:in std_logic;
		f6dnbutton:in std_logic;
		fuplight:buffer std_logic_vector(5 downto 1);
		fdnlight:buffer std_logic_vector(6 downto 2);
		stop1button,stop2button,stop3button:in std_logic;
		stop4button,stop5button,stop6button:in std_logic;
		stoplight:buffer std_logic_vector(6 downto 1);
		position:buffer integer range 1 to 6;
		lightout:out std_logic_vector(6 downto 0);
		doorlight:out std_logic;
		udsig:buffer std_logic);
end lift;

architecture behave of lift is
	type lift_state is
		(stopon1,dooropen,doorclose,doorwait1,doorwait2,doorwait3,doorwait4,
		up,down,stop);
	signal mylift:lift_state;
	signal clearup:std_logic;
	signal cleardn:std_logic;
	
	component display
		PORT(clk: IN STD_LOGIC;--时钟信号
			light: in integer range 1 to 6;--电梯的位置
			segout: OUT STD_LOGIC_VECTOR(6 downto 0));--数码管显示
	end component;
	--component fenpin
	--	PORT(clk: IN STD_LOGIC;
	--		clk1m,clk10,clk1: OUT STD_LOGIC);
	--end component;
begin

u2:display port map(buttonclk,position,lightout);
ctrlift:process(reset,liftclk)
		variable pos:integer range 6 downto 1;
begin 
if reset = '1' then
	mylift <= stopon1;
	clearup <= '0';
	cleardn <= '0';
else
	if liftclk'event and liftclk = '1' then
		case mylift is
			when stopon1 =>
				 doorlight <= '1';
				 position <= 1;
				 pos:=1;
				 mylift <= doorwait1;

			when doorwait1 =>
				mylift <= doorwait2;

			when doorwait2 =>
				 clearup <= '0';
				 cleardn <= '0';
				 mylift <= doorwait3;

			when doorwait3 =>
				mylift <= doorwait4;

			when doorwait4 =>
				mylift <= doorclose;

			when doorclose =>
				doorlight <= '0';
				if udsig = '0' then
					if position = 6 then
						if stoplight = "000000" and fuplight = "00000" and fdnlight = "00000" then
							  udsig <= '1';
							  mylift <= doorclose;
						else 
							udsig <= '1';  mylift <= down;
						end if;
					elsif position = 5 then
						if stoplight = "0000" and fuplight = "00000" and fdnlight = "00000" then
							 udsig <= '0';
							 mylift <= doorclose;
						elsif stoplight(6) = '1' or (stoplight(6) = '0' and fdnlight(6) = '1') then
							 udsig <= '0';
							 mylift <= up;
						else udsig <= '1'; mylift <= down;
						end if;
					elsif position = 4 then
						if stoplight = "000000" and fuplight = "00000" and fdnlight = "00000" then
							 udsig <= '0';
							 mylift <= doorclose;
						elsif stoplight(6) = '1' or (stoplight(6) = '0' and fdnlight(6) = '1') then
							 udsig <= '0';
							 mylift <= up;
						elsif stoplight(5) = '1' or (stoplight(5) = '0' and fdnlight(5) = '1') then
							 udsig <= '0';
							 mylift <= up;
						elsif stoplight(5) = '1' or (stoplight(5) = '0' and fuplight(5) = '1') then
							 udsig <= '0';
							 mylift <= up;
						else udsig <= '1'; mylift <= down;
						end if;
					elsif position = 3 then
						if stoplight = "000000" and fuplight = "00000" and fdnlight = "00000" then
							 udsig <= '0';
							 mylift <= doorclose;
						elsif stoplight(6) = '1' or (stoplight(6) = '0' and fdnlight(6) = '1') then
							 udsig <= '0';
							 mylift <= up;
						elsif stoplight(5) = '1' or (stoplight(5) = '0' and fdnlight(5) = '1') then
							 udsig <= '0';
							 mylift <= up;
						elsif stoplight(5) = '1' or (stoplight(5) = '0' and fuplight(5) = '1') then
							 udsig <= '0';
							 mylift <= up;
						elsif stoplight(4) = '1' or (stoplight(4) = '0' and fdnlight(4) = '1') then
							 udsig <= '0';
							 mylift <= up;
						elsif stoplight(4) = '1' or (stoplight(4) = '0' and fuplight(4) = '1') then
							 udsig <= '0';
							 mylift <= up;
						else 
							udsig <= '1'; 
							mylift <= down;
						end if;
					elsif position = 2 then
						if stoplight = "000000" and fuplight = "00000" and fdnlight = "00000" then
							 udsig <= '0';
							 mylift <= doorclose;
						elsif stoplight(6) = '1' or (stoplight(6) = '0' and fdnlight(6) = '1') then
							 udsig <= '0';
							 mylift <= up;
						elsif stoplight(5) = '1' or (stoplight(5) = '0' and fdnlight(5) = '1') then
							 udsig <= '0';
							 mylift <= up;
						elsif stoplight(5) = '1' or (stoplight(5) = '0' and fuplight(5) = '1') then
							 udsig <= '0';
							 mylift <= up;
						elsif stoplight(4) = '1' or (stoplight(4) = '0' and fdnlight(4) = '1') then
							 udsig <= '0';
							 mylift <= up;
						elsif stoplight(4) = '1' or (stoplight(4) = '0' and fuplight(4) = '1') then
							 udsig <= '0';
							 mylift <= up;
						elsif stoplight(3) = '1' or (stoplight(3) = '0' and fdnlight(3) = '1') then
							 udsig <= '0';
							 mylift <= up;
						elsif stoplight(3) = '1' or (stoplight(3) = '0' and fuplight(3) = '1') then
							 udsig <= '0';
							 mylift <= up;
						else 
							udsig <= '1'; 
							mylift <= down;
						end if;
					elsif position = 1 then
					   if stoplight = "000000" and fuplight = "00000" and fdnlight = "00000" then
							udsig <= '0';
							mylift <= doorclose;
						else 
							udsig <= '0'; 
							mylift <= up;
						end if;
					end if;
				elsif udsig = '1' then
					if position = 1 then
						if stoplight = "000000" and fuplight = "00000" and fdnlight = "00000" then
							udsig <= '0';
							mylift <= doorclose;
						else 
							udsig <= '0'; mylift <= up;
						end if;
					elsif position = 2 then
						if stoplight = "000000" and fuplight = "00000" and fdnlight = "00000" then
							 udsig <= '1';
							 mylift <= doorclose;
						elsif stoplight(1) = '1' or (stoplight(1) = '0' and fuplight(1) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						else
							udsig <= '0'; mylift <= up;
						end if;
					elsif position = 3 then
						if stoplight = "000000" and fuplight = "00000" and fdnlight = "00000" then
							 udsig <= '1';
							 mylift <= doorclose;
						elsif stoplight(2) = '1' or (stoplight(2) = '0' and fdnlight(2) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						elsif stoplight(2) = '1' or (stoplight(2) = '0' and fuplight(2) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						elsif stoplight(1) = '1' or (stoplight(1) = '0' and fuplight(1) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						else
							udsig <= '0'; mylift <= up;
						end if;
					elsif position = 4 then
						if stoplight = "000000" and fuplight = "00000" and fdnlight = "00000" then
							 udsig <= '1';
							 mylift <= doorclose;
						elsif stoplight(3) = '1' or (stoplight(3) = '0' and fdnlight(3) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						elsif stoplight(3) = '1' or (stoplight(3) = '0' and fuplight(3) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						elsif stoplight(2) = '1' or (stoplight(2) = '0' and fdnlight(2) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						elsif stoplight(2) = '1' or (stoplight(2) = '0' and fuplight(2) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						elsif stoplight(1) = '1' or (stoplight(1) = '0' and fuplight(1) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						else
							udsig <= '0'; mylift <= up;
						end if;
					elsif position = 5 then
						if stoplight = "000000" and fuplight = "00000" and fdnlight = "00000" then
							 udsig <= '1';
							 mylift <= doorclose;
						elsif stoplight(4) = '1' or (stoplight(4) = '0' and fdnlight(4) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						elsif stoplight(4) = '1' or (stoplight(4) = '0' and fuplight(4) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						elsif stoplight(3) = '1' or (stoplight(3) = '0' and fdnlight(3) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						elsif stoplight(3) = '1' or (stoplight(3) = '0' and fuplight(3) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						elsif stoplight(2) = '1' or (stoplight(2) = '0' and fdnlight(2) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						elsif stoplight(2) = '1' or (stoplight(2) = '0' and fuplight(2) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						elsif stoplight(1) = '1' or (stoplight(1) = '0' and fuplight(1) = '1' ) then
							 udsig <= '1';
							 mylift <= down;
						else
							udsig <= '0'; mylift <= up;
						end if;
					elsif position = 6 then
						if stoplight = "000000" and fuplight = "00000" and fdnlight = "00000" then
							 udsig <= '1';
							 mylift <= doorclose;
						else 
							udsig <= '1';
							mylift <= down;
						end if;
					end if;
				end if;
			when up =>
				position <= position + 1;
				pos:=pos + 1;
				if pos < 6 and (stoplight(pos) = '1'or fuplight(pos) = '1')then 
					mylift <= stop;
				elsif pos = 6 and (stoplight(pos) = '1' or fdnlight(pos) = '1') then 
					mylift <= stop;
				else 
					mylift <= doorclose;
				end if;
			when down =>
				position <= position - 1;
				pos:=pos - 1;
				if pos > 1 and (stoplight(pos) = '1' or fdnlight(pos) = '1')then 
					mylift <= stop;
				elsif pos = 1 and (stoplight(pos) = '1' or fuplight(pos) = '1')then 
					mylift <= stop;
				else
					mylift <= doorclose;
				end if;
			when stop =>
				mylift <= dooropen;
			when dooropen =>
				doorlight <= '1';
				if udsig = '0' then
					if position<=5 and(stoplight(position) = '1'or fuplight(position)='1')then
						clearup <= '1';
					else 
						clearup <= '1';cleardn <= '1';
					end if;
				elsif udsig = '1' then
					if position>=2 and(stoplight(position) = '1' or fdnlight(position)='1')then
						cleardn <= '1';
					else 
						clearup <= '1';cleardn <= '1';
					end if;
				end if;
				mylift <= doorwait1;
		end case;
	end if;
end if;
end process ctrlift;

ctrlight:process(reset,buttonclk)
begin
	if reset = '1' then
		stoplight<="000000";fuplight<="00000";fdnlight<="00000";
	else
		if buttonclk'event and buttonclk='1' then
			if clearup='1' then
				stoplight(position)<='0';
				fuplight(position)<='0';
			else
				if f1upbutton='1' then
					fuplight(1)<='1';
				elsif f2upbutton='1' then 
					fuplight(2)<='1';
				elsif f3upbutton='1' then 
					fuplight(3)<='1';
				elsif f4upbutton='1' then 
					fuplight(4)<='1';
				elsif f5upbutton='1' then 
					fuplight(5)<='1';
				end if;
			end if;
			if cleardn = '1' then
				stoplight(position)<='0';
				fdnlight(position)<='0';
			else
				if f2dnbutton='1' then
					fdnlight(2)<='1';
				elsif  f3dnbutton='1' then 
					fdnlight(3)<='1';
				elsif  f4dnbutton='1' then 
					fdnlight(4)<='1';
				elsif  f5dnbutton='1' then 
					fdnlight(5)<='1';
				elsif  f6dnbutton='1' then 
					fdnlight(6)<='1';
				end if;
			end if;
			if stop1button = '1' then 
				stoplight(1) <= '1';
			elsif stop2button = '1' then 
				stoplight(2) <= '1';
			elsif stop3button = '1' then 
				stoplight(3) <= '1';
			elsif stop4button = '1' then 
				stoplight(4) <= '1';
			elsif stop5button = '1' then 
				stoplight(5) <= '1';
			elsif stop6button = '1' then 
				stoplight(6) <= '1';
			end if;
		end if;
	end if;
end process ctrlight;
end;

⌨️ 快捷键说明

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