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

📄 display.vhd

📁 用vhdl实现的电子琴中的音乐播放模块
💻 VHD
字号:
--显示模块
--
library ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_arith.all;
Use ieee.std_logic_unsigned.all;

entity display is
port(clk : in std_logic; --扫描时钟
     clk_scint : in std_logic; --闪烁时钟
     state : in std_logic_vector(1 downto 0); --系统当前工作状态
     scint : in std_logic_vector(2 downto 0); --当前状态下的小状态
     time : in std_logic_vector(23 downto 0); --待显示的时间
     num : out std_logic_vector(7 downto 0); --输出到数码管的数据信号
     cs : out std_logic_vector(5 downto 0)); --6个数码管的选通信号
end display;

architecture a of display is

signal dot : std_logic;  --小数点的显示,比如时间显示为:16.30.58
begin
  process(clk)
  variable tmpcs : std_logic_vector(5 downto 0);
  variable tmpnum : std_logic_vector(3 downto 0);
    begin
      if(clk'event and clk='1') then
        case tmpcs is

          when "111110" => tmpcs := "111101"; tmpnum := time(7 downto 4); --第1个数码管->第2个
          when "111101" => tmpcs := "111011"; tmpnum := time(11 downto 8); --第2个数码管->第3个
            if(state="01" or state="10") then   --但是在对时定时状态
              if(scint="001" or scint="100") then --若当前要闪烁的是中间两个数码管
                if(clk_scint='1') then  --那么在clk_scint有效时
                  tmpcs := "101111";   --第2个数码管选通后,直接跳到5个,
                  tmpnum := time(19 downto 16);  --当然,显示的数据也得跟着变            
                end if;
              end if;
            end if;

          when "111011" => tmpcs := "110111"; tmpnum := time(15 downto 12);--第3个数码管->第4个
          when "110111" => tmpcs := "101111"; tmpnum := time(19 downto 16);--第4个数码管->第5个
            if(state="01" or state="10") then  --但是在对时定时状态
              if(scint="010" or scint="101") then --若当前要闪烁的是左边两个数码管
                if(clk_scint='1') then   --那么在clk_scint有效时
                  tmpcs := "111110";  --第4个数码管选通后,直接跳到1个,
                  tmpnum := time(3 downto 0); --当然,显示的数据也得跟着变            
                end if;
              end if;
            end if;

          when "101111" => tmpcs := "011111"; tmpnum := time(23 downto 20);--第5个数码管->第6个
          when "011111" => tmpcs := "111110"; tmpnum := time(3 downto 0);--第6个数码管->第1个
            if(state="01" or state="10") then --但是在对时定时状态
              if(scint="000" or scint="011") then --若当前要闪烁的是右边两个数码管
                if(clk_scint='1') then  --那么在clk_scint有效时
                  tmpcs := "111011";  --第6个数码管选通后,直接跳到3个,
                  tmpnum := time(11 downto 8); --当然,显示的数据也得跟着变        
                end if;
              end if;
            end if;

          when others => tmpcs := "111110"; tmpnum := null;
        end case;

      end if;

      cs <= tmpcs;
      dot <= not tmpcs(2) or not tmpcs(4); --这是小数点的显示,以区分时分秒或年月日等

      case tmpnum is  --这是七段译码器,加上了小数点
        when "0000" => num <= dot&"0111111";
        when "0001" => num <= dot&"0000110";
        when "0010" => num <= dot&"1011011";
        when "0011" => num <= dot&"1001111";
        when "0100" => num <= dot&"1100110";
        when "0101" => num <= dot&"1101101";
        when "0110" => num <= dot&"1111101";
        when "0111" => num <= dot&"0000111";
        when "1000" => num <= dot&"1111111";
        when "1001" => num <= dot&"1101111";
        when others => num <= Null;
      end case;
    end process;
end a;
          

⌨️ 快捷键说明

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