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

📄 ssgdisp.vhd

📁 罗马尼亚克鲁日工程大学Mircea D&#259 b&acirc can, PhD提供的示波器开发全文挡及C,VHDL代码.
💻 VHD
字号:
-- 7 segment display

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity ssgdisp is
  Port (rst  : in std_logic;
        mclk : in std_logic; -- 50 MHz clock
        xval : in std_logic_vector(15 downto 0); -- hexadecimal number to be displayed (four digits)
        ssg  : out std_logic_vector(7 downto 0);
        an   : out std_logic_vector(3 downto 0));
end ssgdisp;

architecture Behavioral of ssgdisp is

-- millisecond counter (exactly 1.3107 ms) the time one digit is displayed on the ssg display
signal ms_cnt : std_logic_vector(15 downto 0); 

-- which digit to display at a given time
signal digcnt : std_logic_vector( 1 downto 0); 

-- the hexa value of the digit
signal hex : std_logic_vector(3 downto 0); 

-- the ssg representation of 'hex'
signal dig : std_logic_vector(6 downto 0); 

begin

-- ms_cnt is resetted every millisecond => period of ms_cnt(15) is 1 ms
process (rst, mclk, ms_cnt)
begin
  if (rst = '1') then
    ms_cnt <= (others => '0');
  elsif (mclk'event and mclk = '1') then
    ms_cnt <= ms_cnt + 1;
  end if;
end process;

-- each digit of the number to be displayed (i.e. xval) is active on then 7 segment display 1 ms
process(rst, ms_cnt(15))
begin
  if (rst = '1') then
    digcnt <= "00";
  elsif (ms_cnt(15)'event and ms_cnt(15) = '1') then
    digcnt <= digcnt + 1;
  end if;
end process;

-- these 4-bit intervals represent (hexa) digits of the number to be displayed
hex <=  xval(15 downto 12) when (digcnt = "00") else
        xval(11 downto 8) when (digcnt = "01") else
        xval(7 downto 4) when (digcnt = "10") else
        xval(3 downto 0) when (digcnt = "11");

-- enable the right anode at the appropriate time
an <=   "1110" when (digcnt = "00") else
        "1101" when (digcnt = "01") else
        "1011" when (digcnt = "10") else
        "0111" when (digcnt = "11");

--    ssg6543210
--       gfedcba
dig <=  "0111111" when hex = "0000" else -- 0
        "0000110" when hex = "0001" else -- 1
        "1011011" when hex = "0010" else -- 2
        "1001111" when hex = "0011" else -- 3
        "1100110" when hex = "0100" else -- 4
        "1101101" when hex = "0101" else -- 5
        "1111101" when hex = "0110" else -- 6
        "0000111" when hex = "0111" else -- 7
        "1111111" when hex = "1000" else -- 8
        "1101111" when hex = "1001" else -- 9
        "1110111" when hex = "1010" else -- A
        "1111100" when hex = "1011" else -- b
        "0111001" when hex = "1100" else -- C
        "1011110" when hex = "1101" else -- d
        "1111001" when hex = "1110" else -- E
        "1110001" when hex = "1111" else -- F
        "0000000";

ssg(6 downto 0) <= not dig;
ssg(7) <= '1';

end Behavioral;

⌨️ 快捷键说明

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