十字路口交通灯指挥系统

设计一个十字路口交通灯指挥系统,主干道和支干道均有红黄绿三种信号灯,要求如下:

1.通常保持主干道绿灯亮,支干道红灯亮,只有当支干道有车时,才转为支干道红灯亮,支干道绿灯亮;

2.绿灯亮转红灯的过程中,先有绿灯转为黄灯3秒钟,再有黄灯转为红灯,同时对方才有红灯转为绿灯;

3.当两个方向都有车时,红绿灯间隔30秒转换一次。


</pre><pre name="code" class="html">library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity traffic is
port(clk0,clkk,clk1:in std_logic;
dout:out std_logic_vector(7 downto 0);
scan:out std_logic_vector(5 downto 0);
light:inout std_logic_vector(7 downto 0);
n1:in std_logic);

end traffic;

architecture a of traffic is
signal flag,temp:std_logic;
signal time1,data,time2:std_logic_vector(3 downto 0):="0000";
begin 
	scan<="0000"&temp&(not temp);
process(clkk)
	begin
		if clkk'event and clkk='1'then
			temp<=not temp;
			if temp='0' then
				data<=time1;
			else data<=time2;
			end if;
		end if;
	end process;

process(clk0)
begin
if clk0'event and clk0='1' then
	if n1='1' then 
		if time1="0000" then
			if time2="0000" then
			time1<="1001";
			time2<="0010";
			flag<=not flag;
			else time2<=time2-1;
			time1<="1001";
			end if;
		else time1<=time1-1;
		end if;
	else 
		time1<="0000";time2<="0000";	
	end if;
	end if;
	end process;

process(time1,flag,time2,n1,clk1)
begin
	if n1='0' then
	light<="00100100";
	elsif n1='1' then
		if time1<"0100" and flag='1' and time2="0000" then
		light(5 downto 0)<="000100";light(7)<='0';--huang  & hong
			if clk1'event and clk1='1' then
			light(6)<=not light(6);
			end if;
		elsif time1<"1010" and flag='1' then
		light<="00100100";--lv & hong
		
		elsif time1<"0100" and flag='0' and time2="0000" then
		light(0)<='0';light(7 downto 2)<="100000";--hong & huang
			if clk1'event and clk1='1' then
			light(1)<=not light(1);
			end if;
		elsif time1<"1010" and flag='0' then
		light<="10000001";--hong & lv
		else null;
		end if;
	end if;
	end process;
	
	
process(data)
begin
case data is
	when "0000"=> dout<="00111111";
	when "0001"=> dout<="00000110";
	when "0010"=> dout<="01011011";
	when "0011"=> dout<="01001111";
	when "0100"=> dout<="01100110";		
	when "0101"=> dout<="01101101";
	when "0110"=> dout<="01111101";
	when "0111"=> dout<="00000111";
	when "1000"=> dout<="01111111";
	when "1001"=> dout<="01101111";
	when "1010"=> dout<="01110111";
	when "1011"=> dout<="01111100";
	when "1100"=> dout<="00111001";
	when "1101"=> dout<="01011110";
	when "1110"=> dout<="01111001";	
	when "1111"=> dout<="00000000";
	when others=> dout<="00000000";
	end case;
	end process;
	end a ;





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值