集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1376|回复: 0

求高手帮我看看交通灯设计,我找不出哪里错了~~

[复制链接]
tangteng55 发表于 2012-4-24 17:43:09 | 显示全部楼层 |阅读模式
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;


ENTITY traffic is
    PORT(
         clk:in std_logic;
         row:out std_logic_vector(1 downto 0);-----xuanzexinhao       
         led:out std_logic_vector(6 downto 0);-----duankongzhixinhao
         R1,Y1,G1,R2,Y2,G2: out std_logic);

END traffic;

architecture Behavioral of traffic is

TYPE states is (st0,st1,st2,st3);
signal sec0:std_logic_vector(3 downto 0);    ----gewei
signal sec1:std_logic_vector(3 downto 0);    ----shiwei
signal cnt:std_logic_vector(1 downto 0);   
signal data:std_logic_vector(3 downto 0);
signal clk1,clk2:std_logic;-----1KHZ  HE 1HZ
BEGIN
     P1:PROCESS(clk)
     variable count1:integer range 0 to 12499; ------25000
     begin
            if rising_edge(clk) then
               if count1=12499 then clk1<=not clk1;
                  count1:=0;
               else count1:=count1+1;
               END if;
            end if;
     END PROCESS P1;
     -------------------------------------------------------------
     P2:process(clk1) ------------1hzfenpin
     variable count2:integer range 0 to 999;
     begin
     if rising_edge(clk1) then
             if count2=999 then clk2<=not clk2;
                count2:=0;
             else count2:=count2+1;
          END if;
     END IF;
     end process P2;
     ------------------
P3:process(clk2)
      variable stx:states;
      variable a:std_logic;
      variable qh,ql:std_logic_vector(3 downto 0);
      begin
      if rising_edge(clk2) then
      case stx is
    when st0=>
             if a='0'then
             qh:="0001";
             ql:="1001";
             a:='1';
             R1<='0';
             Y1<='0';
             G1<='1';
             R2<='1';
             Y2<='0';
             G2<='0';
       ELSE
          if qh=0 and ql=1 then
             stx:=st1;
             a:='0';
             qh:="0000";
             ql:="0000";
          else if ql=0 then
              ql:="1001";
              qh:=qh-1;
          else
              ql:=ql-1;
           end if;
        end if;
       end if;
      when st1=>  
             if a='0'then
           qh:="0000";
           ql:="0011";
             a:='1';
             R1<='0';
             Y1<='1';
             G1<='0';
             R2<='1';
             Y2<='0';
             G2<='0';
         else
              if ql=1 then
                stx:=st2;
                a:='0';
                qh:="0000";
                ql:="0000";
              else
                ql:=ql-1;
              end if;
            end if;
        end if;
       when st2=>
             if a='0'then
                qh:="0000";
                ql:="1001";
              a:='1';
             R1<='1';
             Y1<='0';
             G1<='0';
             R2<='0';
             Y2<='0';
             G2<='1';
         else
             if qh=0 and ql=1 then
                stx:=st3;
                a:='0';
                qh:="0000";
                ql:="0000";
                elsif ql=0 then
                   ql:="1001";
                   qh:=qh-1;
                else
                   ql:=ql-1;
               end if;
             end if;
             end if;
        when st3=>
             if a='0'then
           qh:="0000";
           ql:="0011";
             a:='1';
             R1<='1';
             Y1<='0';
             G1<='0';
             R2<='0';
             Y2<='1';
             G2<='0';
             else
                if ql=1 then
               stx:=st0;
                a:='0';
               qh:="0000";
               ql:="0000";
               else
                  ql:=ql-1;
                  end if;
              end if;
     end if;
     end case;
     end if;
        sec0<=ql;sec1<=qh;
     end process P3;
  -------------------------------------------------------------
P4:PROCESS(clk1)
     begin
        if rising_edge(clk1) then
          if cnt="01" then cnt<="00" ;
                  else cnt<=cnt+1;
                  end if;
        end if;
        END PROCESS P4;
        ---------------------
        P5:PROCESS(cnt,sec0,sec1)
            begin
              case cnt is
               when "00"=>data<=sec0;row<="01";
               when "01"=>data<=sec1;row<="10";
          when others=>null;
          end case;
          end process P5;
        
        -----------------------------------------------------------
     ---dp.g.f.e.d.c.b.a
   P6:process(data)
   begin
   case data is
        when"0000"=>led<="11000000";
        when"0001"=>led<="11111001";
        when"0010"=>led<="10100100";
        when"0011"=>led<="10110000";
        when"0100"=>led<="10011001";
        when"0101"=>led<="10010010";
        when"0110"=>led<="10000010";
        when"0111"=>led<="11111000";
        when"1000"=>led<="10000000";
        when"1001"=>led<="10010000";
        when others=>led<=null;
  end case;
  end process P6;
  END Behavioral;
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|集成电路技术分享 ( 京ICP备20003123号-1 )

GMT+8, 2024-6-28 22:24 , Processed in 0.072633 second(s), 24 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表