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

📄 controller.vhd

📁 交通灯信号控制器
💻 VHD
字号:
--
--  File: controller.vhd
--  控制模块:输入clk1为1HZ时钟信号,reset,输出为LED信号和倒计时值

library IEEE;
use IEEE.std_logic_1164.all;

entity controller is
	port (
		clk1: in STD_LOGIC;
		reset: in STD_LOGIC;
		RedA: out STD_LOGIC;
		RedB: out STD_LOGIC;
		GreenA: out STD_LOGIC;
		GreenB: out STD_LOGIC;
		YellowA: out STD_LOGIC;
		YellowB: out STD_LOGIC;
		NumA: out INTEGER range 0 to 40;
		NumB: out INTEGER range 0 to 40
	);
end controller;	

architecture rtl of controller is 
signal cntA:integer range 0 to 70;  --A:main street 70s;B:slave street 60s.	
signal cntB:integer range 0 to 60;
begin
	process(clk1,reset)	
	begin
		if(reset='1') then
			cntA<=0;
			cntB<=0;
		elsif rising_edge(clk1) then
			if(cntA=69) then cntA<=0;
			else cntA<=cntA+1;
			end if;
			if(cntB=59) then cntB<=0;
			else cntB<=cntB+1;
			end if;	 
		end if;
	end process;
	
	process(clk1,reset)
	begin
		if(reset='1') then 
			RedA<='0';   
			RedB<='0';   
			GreenA<='0'; 
			GreenB<='0'; 
			YellowA<='0';
			YellowB<='0'; 
		elsif rising_edge(clk1)	 then
			if(cntA<20) then	   -- 前20s主干路红灯亮
				RedA<='1';
				GreenA<='0';
				YellowA<='0';
				NumA<=20-cntA;
			elsif(cntA<60) then	   --21-60s主干路绿灯亮
				RedA<='0';
				GreenA<='1';
				YellowA<='0';
				NumA<=60-cntA;
			else            	   --61-70s主干路黄灯亮
				RedA<='0';
				GreenA<='0';
				YellowA<='1';
				NumA<=70-cntA;
			end if;	
			
			if(cntB<20) then	   -- 前20s支干道红灯亮
				RedB<='1';
				GreenB<='0';
				YellowB<='0';
				NumB<=20-cntB;
			elsif(cntB<50) then	   --21-50s支干道绿灯亮
				RedB<='0';
				GreenB<='1';
				YellowB<='0';
				NumB<=50-cntB;
			else            	   --51-60s支干道黄灯亮
				RedB<='0';
				GreenB<='0';
				YellowB<='1';
				NumB<=60-cntB;
			end if;	  
		end if;
	end process;			
end rtl;

⌨️ 快捷键说明

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