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

📄 controla.vhd

📁 VHDL实现的交通灯程序
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity ControlA is
	port(
		clk:in std_logic;
		show:in std_logic:='1';
		timeh,timel:out std_logic_vector(3 downto 0);
		r,g,y,t:out std_logic
		);
end ControlA;

architecture ControlA_arc of ControlA is
type color is(green,yellow,red,turn);
begin
	process(clk,show)
	variable reset:std_logic:='0';
	variable tempr,tempg,tempy,tempt:std_logic;
	variable temp_h,temp_l:std_logic_vector(3 downto 0);
	variable temp_color:color:=green;

	begin
		if(clk'event and clk='1')then
		case show is
			when '0'=>
				case temp_color is
					when yellow=>
						tempr:='0';
						tempg:='0';
						tempy:='1';
						tempt:='0';
						case reset is
						when '0' =>
							temp_h:="0000";
							temp_l:="0100";
							reset:='1';
						when others =>
							case temp_l is
								when "0000"=>
									temp_l:="1001";
									temp_h:=temp_h-1;
								when "0001"=>
									case temp_h is
									when "0000" =>
										temp_h:="0000";
										temp_l:="0000";
										reset:='0';
										temp_color:=red;
									when others =>
										temp_l:="0000";
									end case;
								when others=>
									temp_l:=temp_l-1;
							 end case;
						end case;
					when green=>
						tempr:='0';
						tempg:='1';
						tempy:='0';
						tempt:='0';
						case reset is
						when '0' =>
							temp_h:="0000";
							temp_l:="1001";
							reset:='1';
						when others =>
							case temp_l is
								when "0000"=>
									temp_l:="1001";
									temp_h:=temp_h-1;
								when "0001"=>
									case temp_h is
									when "0000" =>
										temp_h:="0000";
										temp_l:="0000";
										reset:='0';
										temp_color:=turn;
									when others =>
										temp_l:="0000";
									end case;
								when others=>
									temp_l:=temp_l-1;
							 end case;
						end case;
					when red=>
						tempr:='1';
						tempg:='0';
						tempy:='0';
						tempt:='0';
						case reset is
						when '0' =>
							temp_h:="0010";
							temp_l:="0100";
							reset:='1';
						when others =>
							case temp_l is
								when "0000"=>
									temp_l:="1001";
									temp_h:=temp_h-1;
								when "0001"=>
									case temp_h is
									when "0000" =>
										temp_h:="0000";
										temp_l:="0000";
										reset:='0';
										temp_color:=green;
									when others =>
										temp_l:="0000";
									end case;
								when others=>
									temp_l:=temp_l-1;
							 end case;
						end case;
					when turn=>
						tempr:='0';
						tempg:='1';
						tempy:='0';
						tempt:='1';
						case reset is
						when '0' =>
							temp_h:="0000";
							temp_l:="1001";
							reset:='1';
						when others =>
							case temp_l is
								when "0000"=>
									temp_l:="1001";
									temp_h:=temp_h-1;
								when "0001"=>
									case temp_h is
									when "0000" =>
										temp_h:="0000";
										temp_l:="0000";
										reset:='0';
										temp_color:=yellow;
									when others =>
										temp_l:="0000";
									end case;
								when others=>
									temp_l:=temp_l-1;
							 end case;
						end case;
				end case;
			when others=>
				tempr:='1';
				tempg:='0';
				tempy:='0';
				tempt:='0';
			end case;	
		end if;
	timeh<=temp_h;
	timel<=temp_l;
	r<=tempr;
	g<=tempg;
	y<=tempy;
	t<=tempt;
	end process;
end ;

⌨️ 快捷键说明

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