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

📄 jiaotongdeng.txt

📁 1). 用红、绿、黄三色发光二极管作信号灯。主干道为东西向
💻 TXT
字号:
----设计一个十字路口的红、绿、黄三色信号交通灯控制电路

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith;
entity jiaoton is
port(reset,s,clk_in:in std_logic;        ------reset为置位信号,clk_in为50MHZ时钟,
-------s为特殊状态信号
	smga1,smga2,smgb1,smgb2:out std_logic_vector(6 downto 0);	
	outa:out std_logic_vector(5 downto 0));-------主(红、绿、黄)和支(红、绿、黄)
end entity ; 
architecture one of jiaoton is
-------------------------------定义一个四种状态的状态机
TYPE FSM_ST IS(s0,s1,s2,s3);
signal current_state : FSM_ST:=s0;
----------------------------------------------------------------------
signal sma2,smb2:integer range 0 to 9;
signal sma1:integer range 0 to 5;
signal smb1:integer range 0 to 5;
signal sansuo,clk:bit;

begin 
-------------------------------------50MHZ的信号进行分频
process(clk_in)
variable fenpin:integer range 0 to 25000000;
begin
	if clk_in'event and clk_in='1' then 
		if fenpin=0 then fenpin:=25000000;clk<=not(clk);
		else fenpin:=fenpin-1;
		end if;
	end if;
end process;

---------------------------------clk为分频后的秒钟时钟信号
process(clk,reset)
variable tc: integer range 0 to 5;
variable tb: integer range 0 to 55;
variable ta: integer range 0 to 50;
begin
if reset='1' then ta:=50;tb:=55;tc:=0;current_state<=s0;-------开始的时候给主干的计数器赋初值---------50,给支干的计数器赋值55。
elsif  clk'event and clk='1'then-------------------------------有输入时钟出发后,计数器开始计数。
		if s='0'then
			case current_state is--------如果没有突发状况的话,执行下面程序
when s0 => outa<="010100";--------主干绿灯亮50秒,支干亮红灯。然后赋给下--------个状态值,继续计数
						if ta=0  then current_state<=s1;tc:=5;ta:=5;
						else ta:=ta-1;tb:=tb-1;
						end if;						
when s1=>outa<="001100";------------主干亮黄灯5秒,支干继续亮红灯,然后------------继续下个状态。
									if tc=0 then current_state<=s2; tb:=30;ta:=35;
									else tc:=tc-1;ta:=ta-1;tb:=tb-1;
									end if;
			when s2=>outa<="100010";  ---------------主干亮红灯,支干亮绿灯30秒
if tb=0 then current_state<=s3;tc:=5;tb:=5;
							else tb:=tb-1;ta:=ta-1;
							end if;
when s3=>outa<="100001";-----------------主干亮红灯,支干亮黄灯5秒,然后又------把第一个状态的值赋给crurrent_state,-------继续循环下去
if tc=0 then current_state<=s0;ta:=50;tb:=55;
							else tc:=tc-1;ta:=ta-1;tb:=tb-1;
							end if;
			when others=>current_state<=s0;ta:=50;tb:=55;
			end case;
else outa<="100100";sansuo<=not(sansuo);------如果有突发状况时,让等亮亮灭--------灭地不行闪烁
		end if;
end if;
--------------------通过取模,取余,可以得到计数的十位和个位,然后通过数码管来显示时间
sma1<=ta/10;
sma2<=ta rem 10;
smb1<=tb/10;
smb2<=tb rem 10;
 end process;
----------显示主干时间的地位
process(sma2,sansuo,s)
begin
	if s='1' and sansuo='1'then smga2<="1111111";
	else 
		case sma2 is
		when 0 => smga2<="1000000";   --------其中数码管的高位在前面,地位在后面
		when 1 => smga2<="1111001";    -------0表示该段数码管亮,1表示灭
		when 2 => smga2<="0100100";
		when 3 => smga2<="0110000";
		when 4 => smga2<="0011001";
		when 5 => smga2<="0010010";
		when 6 => smga2<="0000010";
		when 7 => smga2<="1111000";
		when 8 => smga2<="0000000";
		when 9 => smga2<="0010000";
		when others => smga2<="1111111";
		end case;
	end if;
end process;
--------------------显示主干时间的高位
process(sma1,s,sansuo)
begin
if s='1' and sansuo='1'then smga1<="1111111";
	else 
	case sma1 is
	when 0 => smga1<="1000000";
	when 1 => smga1<="1111001";
	when 2 => smga1<="0100100";
	when 3 => smga1<="0110000";
	when 4 => smga1<="0011001";
	when 5 => smga1<="0010010";
	when others => smga1<="1111111";
	end case;
end if;
end process;
----------------------------显示支干时间的地位
process(smb2,s,sansuo)
begin
if s='1' and sansuo='1'then smgb2<="1111111";
	else 
	case smb2 is
	when 0 => smgb2<="1000000";
		when 1 => smgb2<="1111001";
		when 2 => smgb2<="0100100";
		when 3 => smgb2<="0110000";
		when 4 => smgb2<="0011001";
		when 5 => smgb2<="0010010";
		when 6 => smgb2<="0000010";
		when 7 => smgb2<="1111000";
		when 8 => smgb2<="0000000";
		when 9 => smgb2<="0010000";
	when others => smgb2<="1111111";
	end case;
end if;
end process;
--------------------------------显示支干时间的高位
process(smb1,s,sansuo)
begin
if s='1' and sansuo='1'then smgb1<="1111111";
	else 
	case smb1 is
		when 0 => smgb1<="1000000";
		when 1 => smgb1<="1111001";
		when 2 => smgb1<="0100100";
		when 3 => smgb1<="0110000";
		when 4 => smgb1<="0011001";
		when 5 => smgb1<="0010010";
	when others => smgb1<="1111111";
	end case;
end if;
end process;
end one;
		-----------------程序结束

⌨️ 快捷键说明

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