交通灯控制

    问题描述,十字路,东西方向和南北方向灯,绿20s黄5s红25s,倒计时显示时间,另外,警车救护车等特殊状态,都显红灯,且时间显示不断闪烁,通过之后,恢复原状态。

    以下是我编写的源代码:

 

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity traffic_light is
     port(clk,special:in std_logic;
           TimeL_show1:buffer std_logic_vector(3 downto 0);--东西计数器低四位
           TimeH_show1:buffer std_logic_vector(3 downto 0);--东西计数器高四位
           TimeL_show2:buffer std_logic_vector(3 downto 0);--南北计数器低四位
           TimeH_show2:buffer std_logic_vector(3 downto 0);--南北计数器高四位
           light1:buffer std_logic_vector(2 downto 0);--东西方向灯
           light2:buffer std_logic_vector(2 downto 0);--南北方向灯         
           );
end entity traffic_light;
architecture behv of traffic_light is
signal TimeL,TimeH:std_logic_vector(3 downto 0);
begin
light1<="100";--东西绿
light2<="001";--南北黄
TimeL<="0000";
TimeH<="0101";
if special='0' then
if clk'event and clk='1' then
l1:loop
   if TimeL<="0000" then
      TimeH<=TimeH-1;
      TimeL<="1001";
      TimeL<=TimeL-1;
   if TimeL<="0000" then
      TimeH<=TimeH-1;
   if TimeL="0000" and TimeH="0000" then
      TimeL<="0000";
      TimeH<="0010";  
end if;
end if;
end if;
  
exit l1 when special='1';
end loop l1;
end if;
end if;
process(TimeL,TimeH,clk,special)
begin
   case TimeL and TimeH is
   when TimeL="0000" and TimeH="0101" => light1<="100"
                                         light2<="001";
if clk'event and clk='1' and special='1' then
    
     TimeL_show1<="0000";
     TimeH_show1<="0010";--绿20s
     TimeL_show1<="0101";
     TimeH_show1<="0010";--红25s
     if TimeL_show1="0000" then
     TimeH_show1<=TimeH_show1-1;
     TimeL_show1<="1001";
     TimeL_show1<=TimeL_show1-1;
    if TimeL_show1="0000" then
    
     TimeH_show1<=TimeH_show1-1;
     end if;
     end if;
    
    if TimeL_show2="0000" then
     TimeH_show2<=TimeH_show2-1;
     TimeL_show2<="1001";
     TimeL_show2<=TimeL_show2-1;
    if TimeL_show2="0000" then
    
     TimeH_show2<=TimeH_show2-1;
     end if;
     end if;
if special='0' then
     light1<="001";
     light2<="001";
     l2:loop
        TimeL_show1<=TimeL_show1;
        TimeH_show1<=TimeH_show1;
        TimeL_show2<=TimeL_show2;
        TimeH_show2<=TimeH_show2;
     exit l2 when special='0';
end loop l2;
end if;
end if;
   when TimeL="0000" and TimeH="0011" => light1<="010"
                                         light2<="001";
if clk'event and clk='1' and special='1' then
    
     TimeL_show1<="0101";
     TimeH_show1<="0000";--黄5s
     TimeL_show2<="0101";
     TimeH_show2<="0000";--红5s
     TimeL_show1<=TimeL_show1-1;
    
     TimeL_show2<=TimeL_show2-1;
    
if special='0' then
     light1<="001";
     light2<="001";
     l3:loop
        TimeL_show1<=TimeL_show1;
        TimeH_show1<=TimeH_show1;
        TimeL_show2<=TimeL_show2;
        TimeH_show2<=TimeH_show2;
     exit l3 when special='0';
end loop l3;
end if;
end if;
   when TimeL="0101" and TimeH="0010" => light1<="001"
                                        light2<="010";

if clk'event and clk='1' and special='1' then
    
     TimeL_show1<="0101";
     TimeH_show1<="0010";--红5s
     TimeL_show2<="0101";
     TimeH_show2<="0000";--黄5s
     TimeL_show1<=TimeL_show1-1;
     TimeL_show2<=TimeL_show2-1;
if special='0' then
     light1<="001";
     light2<="001";
     l4:loop
        TimeL_show1<=TimeL_show1;
        TimeH_show1<=TimeH_show1;
        TimeL_show2<=TimeL_show2;
        TimeH_show2<=TimeH_show2;
     exit l4 when special='0';
end loop l4;
end if;
end if;
    when TimeL="0000" and TimeH="0010" => light1<="001"
                                        light2<="100";
if clk'event and clk='1' and special='1' then
    
     TimeL_show1<="0000";
     TimeH_show1<="0010";--红20s
     TimeL_show2<="0000";
     TimeH_show2<="0010";--绿20s
     if TimeL_show1="0000" then
     TimeH_show1<=TimeH_show1-1;
     TimeL_show1<="1001";
     TimeL_show1<=TimeL_show1-1;
    if TimeL_show1="0000" then
    
     TimeH_show1<=TimeH_show1-1;
     end if;
     end if;
     if TimeL_show2="0000" then
     TimeH_show2<=TimeH_show2-1;
     TimeL_show2<="1001";
     TimeL_show2<=TimeL_show2-1;
    if TimeL_show2="0000" then
    
     TimeH_show2<=TimeH_show2-1;
    end if;
    end if;
if special='0' then
     light1<="001";
     light2<="001";
     l5:loop
        TimeL_show1<=TimeL_show1;
        TimeH_show1<=TimeH_show1;
        TimeL_show2<=TimeL_show2;
        TimeH_show2<=TimeH_show2;
     exit l5 when special='0';
end loop l5;
end if;
end if;
end case;
end process;
end behv;    
 总结:调试有错误,待修正,希望能和大家多交流。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值