-- Filename ﹕ LED_SEG7.vhd
-- Author ﹕ wuhouhang
-- Description ﹕ 2位數碼管每隔640ms從0-F循環遞增顯示
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
entity LED_SEG7 is
port(
Clk: in STD_LOGIC; --50MHz輸入時鐘
Rst_n: in STD_LOGIC; --低電平復位信號
Sm_cs_n_out: out STD_LOGIC_VECTOR (1 downto 0); --2位數碼管位選信號,低電平有效
Sm_db_out: buffer STD_LOGIC_VECTOR (6 downto 0) --2位數碼管斷選信號(不包括小數點)
);
end entity LED_SEG7;
--640ms計數產生0-F遞增數值
--數碼管段選譯碼顯示
architecture SEG_DISPLAY of LED_SEG7 is
signal cnt640ms: STD_LOGIC_VECTOR (24 downto 0); --640ms計數寄存器
signal num: STD_LOGIC_VECTOR (3 downto 0); --每640ms遞增數值寄存器
begin
--640ms計數
process(Clk,Rst_n)
begin
if (Rst_n = '0') then --異步復位
cnt640ms <= b"0" & x"000000";
elsif (Clk'event AND Clk = '1') then --時鐘上升沿
if (cnt640ms < 10#32000000#) then --320ms計數
cnt640ms <= cnt640ms+1;
else
cnt640ms <= b"0" & x"000000";
end if;
end if;
end process;
--產生每640ms遞增的0-F值
process(Clk,Rst_n)
begin
if (Rst_n = '0') then --異步復位
num <= x"0";
elsif (Clk'event AND Clk = '1') then --時鐘上升沿
if (cnt640ms = 10#32000000#) then --320ms計數
num <= num+1;
end if;
end if;
end process;
--段選顯示值譯碼
process(Clk,Rst_n)
begin
if (Rst_n = '0') then --異步復位
Sm_db_out <= "0000000";
elsif (Clk'event AND Clk = '1') then --時鐘上升沿
case num is
when x"0" => Sm_db_out <= "0111111"; --顯示“0”
when x"1" => Sm_db_out <= "0000110"; --顯示“1”
when x"2" => Sm_db_out <= "1011011"; --顯示“2”
when x"3" => Sm_db_out <= "1001111"; --顯示“3”
when x"4" => Sm_db_out <= "1100110"; --顯示“4”
when x"5" => Sm_db_out <= "1101101"; --顯示“5”
when x"6" => Sm_db_out <= "1111101"; --顯示“6”
when x"7" => Sm_db_out <= "0000111"; --顯示“7”
when x"8" => Sm_db_out <= "1111111"; --顯示“8”
when x"9" => Sm_db_out <= "1101111"; --顯示“9”
when x"a" => Sm_db_out <= "1110111"; --顯示“A”
when x"b" => Sm_db_out <= "1111100"; --顯示“B”
when x"c" => Sm_db_out <= "0111001"; --顯示“C”
when x"d" => Sm_db_out <= "1011110"; --顯示“D”
when x"e" => Sm_db_out <= "1111001"; --顯示“E”
when x"f" => Sm_db_out <= "1110001"; --顯示“F”
when others => Sm_db_out <= "0000000";
end case;
end if;
end process;
--位選有效
Sm_cs_n_out <= "00";
end architecture SEG_DISPLAY;
評論
查看更多