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

📄 四层电梯vhdl.txt

📁 四层电梯vhdl 1、 每层电梯的入口处设有上下请求开关
💻 TXT
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;


entity flift is

port(clk,reset,up1,up2,up3,down2,down3,down4,stop1,stop2,stop3,stop4: in std_logic;
	uplight,downlight,stoplight: buffer std_logic_vector(4 downto 1);
	udsig:buffer std_logic;
	position:buffer integer range 1 to 4;
	cdisplay:out std_logic_vector(3 downto 0); 	--楼层显示
	tdisplay:out std_logic_vector(3 downto 0); 	--5秒倒计时
	doorlight:out std_logic);
end;

architecture behav of flift is

type state_type is(stopon1,dooropen,doorclose,wait1,wait2,wait3,wait3,wait4,wait5,wait6,wait7,wait8,up,down,stop,
		swup2,swup3,swup4,swup5,swdn2,swdn3,swdn4,swdn5);
signal state:state_type:=stopon1;
signal clearup,cleardn:std_logic;
 
begin

zhuang_tai:process(clk,reset)	--clk 1HZ 脉冲
variable pos: integer range 4 downto 1;
begin
if reset='1'then
	state<=stopon1;
	clearup<='0';
	cleardn<='0';
elsif rising_edge (clk) then

	case state is

		when stopon1=>doorlight<='1';position<=1;pos:=1;state<=wait1;udsig<='0';cdisplay<="0001";	--初始状态
		when wait1=>state<=wait2;	--停8秒
		when wait2=>clearup<='0';cleardn<='0';state<=wait3;
		when wait3=>state<=wait4;
		when wait4=>state<=wait5;
		when wait5=>state<=wait6;
		when wait6=>state<=wait7;
		when wait7=>state<=wait8;
		when wait8=>state<=doorclose;
		when doorclose=>doorlight<='0';
		
		if udsig='0' then 	--上升情况
			if position=4 then  	--电梯在四楼
				if stoplight="0000"and uplight="0000"and downlight="0000" then
				udsig<='1';state<=doorclose;
				else 
				udsig<='1';state<=down;
				end if;
			elsif position=3 then  	--电梯在三楼
				if stoplight="0000"and uplight="0000"and downlight="0000" then
				udsig<='0';state<=doorclose;
				elsif stoplight(4)='1' or downlight(4)='1' then
				udsig<='0';state<=up;
				else
				udsig<='1';state<=down;
				end if;
			elsif position=2 then 	--电梯在二楼
				if stoplight="0000"and uplight="0000"and downlight="0000" then
				udsig<='0';state<=doorclose;
				elsif stoplight(3)='1'or uplight(3)='1'or stoplight(4)='1'or downlight(4)='1' then
				udsig<='0';state<=up;
				else
				udsig<='1';state<=down;
				end if;
			elsif position=1 then 	--电梯在一楼
				if stoplight="0000"and uplight="0000"and downlight="0000" then
				udsig<='0';state<=doorclose;
				else
				udsig<='0';state<=up;
				end if;
			end if;
		elsif udsig='1' then --下降情况
			if position=1 then 	--电梯在一楼
				if stoplight="0000"and uplight="0000"and downlight="0000" then
				udsig<='0';state<=doorclose;
				else
				udsig<='0';state<=up;
				end if;
			elsif position=2 then 	--电梯在二楼
				if stoplight="0000"and uplight="0000"and downlight="0000" then
				udsig<='1';state<=doorclose;
				elsif stoplight(1)='1'or uplight(1)='1' then
				udsig<='1';state<=down;
				else 
				udsig<='0';state<=up;
				end if;
			elsif position=3 then 	--电梯在三楼
				if stoplight="0000"and uplight="0000"and downlight="0000" then
				udsig<='1';state<=doorclose;
				elsif stoplight(2)='1'or downlight(2)='1'or stoplight(1)='1'or uplight(1)='1' then
				udsig<='1';state<=down;
				else
				udsig<='0';state<=up;
				end if;
			elsif position=4 then 	--电梯在四楼
				if stoplight="0000"and uplight="0000"and downlight="0000" then
				udsig<='1';state<=doorclose;
				else
				udsig<='1';state<=down;
				end if;
			end if;
		end if;
		when up=>state<=swup5;tdisplay<="0101"; 	--显示5
		when swup5=>state<=swup4;tdisplay<="0100"; 	--显示4
		when swup4=>state<=swup3;tdisplay<="0011"; 	--显示3
		when swup3=>state<=swup2;tdisplay<="0010";	--显示2
		when swup2=>tdisplay<="0001";			--显示1
			position<=position+1;pos:=pos+1;	--上升一层,并耗时5秒
			if position=1 then cdisplay<="0001"; 	--显示第1层
			elsif position=2 then cdisplay<="0010";	--显示第2层
			elsif position=3 then cdisplay<="0011";	--显示第3层
			elsif position=4 then cdisplay<="0100";	--显示第4层
			else cdisplay<="0000";
			end if; 

			if pos=2 and (stoplight(3)='1'or uplight(3)='1'or stoplight(4)='1'or downlight(4)='1')then
			state<=up;
			elsif pos=3 and (stoplight(4)='1'or downlight(4)='1') then
			state<=up;
			else
			state<=stop;
			tdisplay<="0000";
			end if;
		when down=>state<=swdn5;tdisplay<="0101";	--显示5
		when swdn5=>state<=swdn4;tdisplay<="0100";	--显示4
		when swdn4=>state<=swdn3;tdisplay<="0011";	--显示3
		when swdn3=>state<=swdn2;tdisplay<="0010";	--显示2
		when swdn2=>tdisplay<="0001";			--显示1
			position<=position-1;pos:=pos-1; 	--下一层,并耗时五秒

			if position=1 then cdisplay<="0001"; 	--显示第1层
			elsif position=2 then cdisplay<="0010";	--显示第2层
			elsif position=3 then cdisplay<="0011";	--显示第3层
			elsif position=4 then cdisplay<="0100";	--显示第4层
			else cdisplay<="0000";
			end if;
 
			if pos=3 and (stoplight(2)='1'or downlight(2)='1'or stoplight(1)='1'or uplight(1)='1') then
			state<=down;
			elsif pos=2 and(stoplight(1)='1'or uplight(1)='1') then
			state<=down;
			else
			state<=stop;
			tdisplay<="0000";
			end if;
		when stop=>state<=dooropen; 	
		when dooropen=>doorlight<='1';clearup<='1';cleardn<='1';state<=wait1;
		when others=>state<=stopon1;
	end case;
end if;
end process zhuang_tai;

shu_ru:process(clk) --读按键,控制指示灯
begin
if reset='1' then
	stoplight<="0000";uplight<="0000";downlight<="0000";
else
if rising_edge(clk) then
	if clearup='1' then
		stoplight(position)<='0';uplight(position)<='0';
	else
		if up1='1'then uplight(1)<='1';end if;
		if up2='1'then uplight(2)<='1';end if;
		if up3='1'then uplight(3)<='1';end if;
	
	end if;
	if cleardn='1' then
		stoplight(position)<='0';downlight(position)<='0';
	else
		if down2='1'then downlight(2)<='1';end if;
		if down3='1'then downlight(3)<='1';end if;
		if down4='1'then downlight(4)<='1';end if;

	end if;

	if stop1='1' then stoplight(1)<='1';end if;
	if stop2='1' then stoplight(2)<='1';end if;
	if stop3='1' then stoplight(3)<='1';end if;
	if stop4='1' then stoplight(4)<='1';end if;
	if stop1='1' then stoplight(1)<='1';
	--elsif stop2='1' then stoplight(2)<='1';
	--elsif stop3='1' then stoplight(3)<='1';
	--elsif stop4='1' then stoplight(4)<='1';
	--end if;

end if;
end if;
end process shu_ru;

--xian_shi:process(position)
--begin

--if position=1 then cdisplay<="0001"; 		--显示第1层
--elsif position=2 then cdisplay<="0010";	--显示第2层
--elsif position=3 then cdisplay<="0011";	--显示第3层
--elsif position=4 then cdisplay<="0100";	--显示第4层
--else cdisplay<="0000";
--end if; 

--end process xian_shi; 
end behav;

⌨️ 快捷键说明

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