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

📄 traffic_con.vhd

📁 一个用VHDL编写的在CPLD上实现模拟交通灯的程序源代码
💻 VHD
字号:
library ieee;
use  ieee.std_logic_1164.all;
use  ieee.std_logic_unsigned.all;

entity traffic_con  is
port(clk  :  in  std_logic;
     reset:  in  std_logic;
     lampa,lampb:  out std_logic_vector(2 downto 0);
     leda,ledb  :  out std_logic_vector(7 downto 0)
     );
end  traffic_con;

architecture  behave  of  traffic_con is


signal  statea :std_logic_vector(2 downto 0);
signal  stateb :std_logic_vector(2 downto 0);
signal  reda,yellowa,greena : std_logic_vector(7 downto 0);
signal  redb,yellowb,greenb : std_logic_vector(7 downto 0);  
signal  counta,countb       : std_logic_vector(7 downto 0);
     
begin
 
  pacon:process(reset,clk)
       variable   tempa:std_logic;
       begin
         if(reset='0') then  tempa:='0';statea<="000";counta<="00000000";lampa<="100";
                             reda<="01010101"; yellowa<="00010000";greena<="00110000";
         elsif(clk'event and clk='1') then
             if(tempa='0')  then
                  --statea<=next_statea;
                  tempa:='1';
                  case  statea  is
                  when  "000"     =>
                               lampa<="100";
                               statea<="001";
                  when  "001"   =>
                               lampa<="100";
                               counta<=reda;
                               statea<="010";
                  when  "010"    =>
                               lampa<="100";
                               statea<="011";
                  when  "011"   =>
                               lampa<="001";
                               counta<=greena;
                               statea<="100";
                  when  "100"    =>
                              lampa<="010";
                              counta<=yellowa;
                              statea<="001";
                  when  others  =>null;
                  end  case;
              else  
                if(counta="00000000") then  tempa:='0';
                else
                         if(counta(3 downto 0)="0000") then counta(3 downto 0)<="1001";
                                                            counta(7 downto 4)<= counta(7 downto 4)-1;
                                               if(counta(7 downto 4)="0000")  then
                                               else  counta(7 downto 4)<=counta(7 downto 4)-1;
                                               end if;
                         else  counta(3 downto 0)<=counta(3 downto 0)-1;
                         end if;
               
                end  if;
            end if;
          end if;
       end  process pacon;

   pbcon:process(reset,clk)
       variable   tempb:std_logic;
       begin
         if(reset='0') then  tempb:='0';stateb<="000";countb<="00000000";lampb<="100";
                             redb<="01000000"; greenb<="01010000";yellowb<="00000101";
         elsif(clk'event and clk='1') then
             if(tempb='0')  then
                  --stateb<=next_stateb;
                  tempb:='1';
                  case  stateb  is
                  when  "000"     =>
                               lampb<="100";
                               stateb<="001";
                  when  "001"    =>
                               lampb<="001";
                               countb<=greenb;
                               stateb<="010";
                  when  "010"   =>
                               lampb<="010";
                               countb<=yellowb;
                               stateb<="011";
                  when  "011"    =>
                               lampb<="100";
                               countb<=redb;
                               stateb<="100";
                  when  "100"    =>
                              lampb<="100";
                              
                              stateb<="001";
                  when  others  =>null;
                  end  case;
              else  
                if(countb="00000000") then   tempb:='0';
                else
                        if(countb(3 downto 0)="0000") then countb(3 downto 0)<="1001";
                                                           countb(7 downto 4)<= countb(7 downto 4)-1;
                                      if(countb(7 downto 4)="0000")  then  
                                      else  countb(7 downto 4)<=countb(7 downto 4)-1;
                                      end if;
                        else  countb(3 downto 0)<=countb(3 downto 0)-1;
                         end if;
              
                end  if;
            end if;
         end if;
       end process pbcon;
   leda<=counta;
   ledb<=countb;

end behave;
                                    
                            
                                    
                                   

⌨️ 快捷键说明

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