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

📄 snake.vhd

📁 利用VHDL语言编写的一个蛇形的程序
💻 VHD
字号:
--(3)控制模块
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity snake is
port(clk:in std_logic;                               
     rst:in std_logic;                             ---复位按键,低有效
     cnt:out std_logic_vector(7 downto 0);           ---显示圈数
     q  :out std_logic_vector(31 downto 0));         ---蛇行状态显示输出,为32位静态显示
end;
architecture snake of snake is
signal count:std_logic_vector(4 downto 0);           ---计每圈状态数
signal count1:std_logic_vector(1 downto 0);          ---计圈数
signal sign :std_logic;                            ---正转翻转标志
signal q1   :std_logic_vector(31 downto 0);          ---蛇行状态寄存器
signal q2   :std_logic_vector(7 downto 0);           ---圈数显示寄存器
begin
process(rst,clk)
begin
if(rst='0')then                                    ---系统复位
    count<=(others=>'0');
    count1<=(others=>'0');
    sign<='0';
    q2<=(others=>'0');
    q1<=(others=>'0');
elsif(clk'event and clk='1')then
        if(sign='0')then                             ---正转
           if(count="10011")then
              if(count1="11")then
                 count1<=(others=>'0');
                 count<=(others=>'0');
                 sign<= not sign;
              else count1<=count1+1;
                   count<=(others=>'0');
              end if;
           else count<=count+1;
           end if;
           case count1 is
           when "00" => q2 <="01100000";
           when "01" => q2 <="11011010";
           when "10" => q2 <="11110010";
           when others=>q2 <="01100110";
           end case;
           case count is                             ---正转状态
           when "00000" => q1 <="10000000100000001000000000000000";
           when "00001" => q1 <="00000000100000001000000010000000";
           when "00010" => q1 <="00000000000000001000000011000000";
           when "00011" => q1 <="00000000000000000000000011000010";
           when "00100" => q1 <="00000000000000000000001001000010";
           when "00101" => q1 <="00000000000000100000001000000010";
           when "00110" => q1 <="00000010000000100000001000000000";
           when "00111" => q1 <="00001010000000100000000000000000";
           when "01000" => q1 <="00011010000000000000000000000000";
           when "01001" => q1 <="00011000000100000000000000000000";
           when "01010" => q1 <="00010000000100000001000000000000";
           when "01011" => q1 <="00000000000100000001000000010000";
           when "01100" => q1 <="00000000000000000001000000110000";
           when "01101" => q1 <="00000000000000000000000000110010";
           when "01110" => q1 <="00000000000000000000001000100010";
           when "01111" => q1 <="00000000000000100000001000000010";
           when "10000" => q1 <="00000010000000100000001000000000";
           when "10001" => q1 <="00000110000000100000000000000000";
           when "10010" => q1 <="10000110000000000000000000000000";
           when "10011" => q1 <="10000100100000000000000000000000";
           when others  => q1 <=(others=>'0');
           end case;
        else if(count="10011")then               ---翻转
              if(count1="11")then
                 count1<=(others=>'0');
                 count<=(others=>'0');
                 sign<= not sign;
              else count1<=count1+1;
                   count<=(others=>'0');
              end if;
             else count<=count+1;
             end if;
           case count1 is
           when "00" => q2 <="01100000";
           when "01" => q2 <="11011010";
           when "10" => q2 <="11110010";
           when others=>q2 <="01100110";
           end case;
           case count is                          ---翻转状态
           when "00000" => q1 <="10000000100000001000000000000000";
           when "00001" => q1 <="10000100100000000000000000000000";
           when "00010" => q1 <="10000110000000000000000000000000";
           when "00011" => q1 <="00000110000000100000000000000000";
           when "00100" => q1 <="00000010000000100000001000000000";
           when "00101" => q1 <="00000000000000100000001000000010";
           when "00110" => q1 <="00000000000000000000001000100010";
           when "00111" => q1 <="00000000000000000000000000110010";
           when "01000" => q1 <="00000000000000000001000000110000";
           when "01001" => q1 <="00000000000100000001000000010000";
           when "01010" => q1 <="00010000000100000001000000000000";
           when "01011" => q1 <="00011000000100000000000000000000";
           when "01100" => q1 <="00011010000000000000000000000000";
           when "01101" => q1 <="00001010000000100000000000000000";
           when "01110" => q1 <="00000010000000100000001000000000";
           when "01111" => q1 <="00000000000000100000001000000010";
           when "10000" => q1 <="00000000000000000000001001000010";
           when "10001" => q1 <="00000000000000000000000011000010";
           when "10010" => q1 <="00000000000000001000000011000000";
           when "10011" => q1 <="00000000100000001000000010000000";
           when others  => q1 <=(others=>'0');
           end case;
       end if;
end if;
end process;
q<=q1;
cnt<=q2;
end;

⌨️ 快捷键说明

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