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

📄 counter.vhd

📁 1.初始状态为4个方向的红灯全亮
💻 VHD
字号:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;

entity counter is
    port( CLK       :IN STD_LOGIC;
          emergency :IN STD_LOGIC;
          lamp    :OUT STD_LOGIC_VECTOR(5 DOWNTO 0);
          HOput   :OUT STD_LOGIC_VECTOR (3 DOWNTO 0);
          LOput   :OUT STD_LOGIC_VECTOR (3 DOWNTO 0)
        );
end counter;

architecture counter_arch of counter is
signal count: UNSIGNED(5 DOWNTO 0);
signal light     : STD_LOGIC_VECTOR ( 5 DOWNTO 0);
signal Houtput   : STD_LOGIC_VECTOR ( 3 DOWNTO 0);
signal Loutput   : STD_LOGIC_VECTOR (3 DOWNTO 0);

begin
process ( CLK )
   begin
      if( CLK'event and CLK='1' ) then
        if( emergency = '0' ) then
         count <= count+1;
        End if;
                           
          if( count=0 ) then    Houtput <= "0000"; Loutput <="0001";

          elsif( count=1 ) then 
            Houtput <= "0011"; Loutput <="0000";
          elsif( count=2 ) then 
            Houtput <= "0010"; Loutput <="1001";
          elsif( count=3 ) then
            Houtput <= "0010"; Loutput <="1000";
          elsif( count=4 ) then 
            Houtput <= "0010"; Loutput <="0111";
          elsif( count=5 ) then 
            Houtput <= "0010"; Loutput <="0110";
          elsif( count=6 ) then 
            Houtput <= "0010"; Loutput <="0101";
          elsif( count=7 ) then
            Houtput <= "0010"; Loutput <="0100";
          elsif( count=8 ) then 
            Houtput <= "0010"; Loutput <="0011";
          elsif( count=9 ) then 
            Houtput <= "0010"; Loutput <="0010";
          elsif( count=10) then
            Houtput <= "0010"; Loutput <="0001";                   
          elsif( count=11) then
            Houtput <= "0010"; Loutput <="0000";
          elsif( count=12) then
            Houtput <= "0001"; Loutput <="1001";
          elsif( count=13) then
            Houtput <= "0001"; Loutput <="1000";
          elsif( count=14) then
            Houtput <= "0001"; Loutput <="0111";
          elsif( count=15) then 
            Houtput <= "0001"; Loutput <="0110";
          elsif( count=16) then
            Houtput <= "0001"; Loutput <="0101";
          elsif( count=17) then
            Houtput <= "0001"; Loutput <="0100";
          elsif( count=18) then
            Houtput <= "0001"; Loutput <="0011";
          elsif( count=19) then
            Houtput <= "0001"; Loutput <="0010";
          elsif( count=20) then
            Houtput <= "0001"; Loutput <="0001";
          elsif( count=21) then
            Houtput <= "0001"; Loutput <="0000";
          elsif( count=22) then
            Houtput <= "0000"; Loutput <="1001";
          elsif( count=23) then
            Houtput <= "0000"; Loutput <="1000";
          elsif( count=24) then
            Houtput <= "0000"; Loutput <="0111";             
          elsif( count=25) then
            Houtput <= "0000"; Loutput <="0110";
          elsif( count=26) then 
            Houtput <= "0000"; Loutput <="0101";
          elsif( count=27) then
            Houtput <= "0000"; Loutput <="0100";
          elsif( count=28) then
            Houtput <= "0000"; Loutput <="0011";
          elsif( count=29) then
            Houtput <= "0000"; Loutput <="0010";
          elsif( count=30) then
            Houtput <= "0000"; Loutput <="0001";
          elsif( count=31) then
            Houtput <= "0000"; Loutput <="0000";

          elsif( count=32) then
            Houtput <= "0000"; Loutput <="0010";
          elsif( count=33) then 
            Houtput <= "0000"; Loutput <="0001";
          elsif( count=34) then
            Houtput <= "0000"; Loutput <="0000";

          elsif( count=35) then 
            Houtput <= "0001"; Loutput <="0101";
          elsif( count=36) then
            Houtput <= "0001"; Loutput <="0100";
          elsif( count=37) then
            Houtput <= "0001"; Loutput <="0011";
          elsif( count=38) then
            Houtput <= "0001"; Loutput <="0010";
          elsif( count=39) then
            Houtput <= "0001"; Loutput <="0001";
          elsif( count=40) then
            Houtput <= "0001"; Loutput <="0000";
          elsif( count=41) then 
            Houtput <= "0000"; Loutput <="1001";
          elsif( count=42) then
            Houtput <= "0000"; Loutput <="1000";                
          elsif( count=43) then 
            Houtput <= "0000"; Loutput <="0111";
          elsif( count=44) then
            Houtput <= "0000"; Loutput <="0110";
          elsif( count=45) then
            Houtput <= "0000"; Loutput <="0101";
          elsif( count=46) then
            Houtput <= "0000"; Loutput <="0100";
          elsif( count=47) then
            Houtput <= "0000"; Loutput <="0011";
          elsif( count=48) then
            Houtput <= "0000"; Loutput <="0010";         
          elsif( count=49) then
            Houtput <= "0000"; Loutput <="0001";
          elsif( count=50) then
            Houtput <= "0000"; Loutput <="0000";
 
          elsif( count=51) then 
            Houtput <= "0000"; Loutput <="0010";
          elsif( count=52) then
            Houtput <= "0000"; Loutput <="0001";
          elsif( count=53) then 
            Houtput <= "0000"; Loutput <="0000";
       end if;
          
          IF( count = 0 AND emergency = '0') THEN 
              light <= "100100";
          ELSIF( count = 1 AND emergency = '0' ) THEN 
              light <= "001100";
          ELSIF( count = 32  ) THEN
              light <= "010100";
          ELSIF( count = 35 AND emergency = '0' ) THEN
            light <= "100001";
          ELSIF( count = 51 AND emergency = '0' ) THEN
            light <= "100010";
          ELSIF( count = 54 AND emergency = '0' ) THEN
            light <= "001100";
            count <= ('0','0','0','0','1','0');
            Houtput <= "0011";
         end if;
  end if;
       HOput <= Houtput;    LOput <= Loutput;
       IF( emergency = '1' ) THEN
        lamp <= "100100";
       ELSE
        lamp <= light; 
       END IF;
        
 end process;
end counter_arch;



⌨️ 快捷键说明

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