?? dynamic_display.vhd
字號:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
--動態顯示模塊,主要目的實現數碼管和發光二極管同時顯示
entity dynamic_display is
Port ( clk : in std_logic; --系統時鐘
reset: in std_logic; --復位信號
datain1,datain2: in std_logic_vector(3 downto 0); --倒計時的數據輸入
data_ledfa:in std_logic_vector(7 downto 0 ); --交通燈的亮滅信號輸入
cs:out std_logic_vector(1 downto 0); --數碼管和發光二極管的選通信號
shift: out std_logic_vector(3 downto 0);--點亮數碼管的位選信號
led : out std_logic_vector(7 downto 0)); --送去顯示的數據輸出
end dynamic_display;
architecture Behavioral of dynamic_display is
signal clk_shift:std_logic;
signal datain11,datain22: std_logic_vector(7 downto 0);
begin
process(clk) --分頻器;
variable cnt : integer range 0 to 5000;
begin
if clk'event and clk='1' then cnt:=cnt+1;
if cnt<2500 then clk_shift<='1';
elsif cnt<5000 then clk_shift<='0';
else cnt:=0;clk_shift<='0';
end if;
end if;
end process;
process(clk_shift,datain1) --譯碼,把十進制數譯成數碼管顯示的段碼
begin
if clk_shift'event and clk_shift='1' then
case datain1 is
when"0000"=>datain11<="01000000";--0
when"0001"=>datain11<="01111001";--1
when"0010"=>datain11<="00100100";--2
when"0011"=>datain11<="00110000";--3
when"0100"=>datain11<="00011001";--4
when"0101"=>datain11<="00010010";--5
when"0110"=>datain11<="00000010";--6
when"0111"=>datain11<="01111000";--7
when"1000"=>datain11<="00000000";--8
when"1001"=>datain11<="00010000";--9
when others=>datain11<="11111111";--No signal;
end case;
end if;
end process;
process(clk_shift,datain2) --譯碼,把十進制數譯成數碼管顯示的段碼
begin
if clk_shift'event and clk_shift='1' then
case datain2 is
when"0000"=>datain22<="01000000";--0
when"0001"=>datain22<="01111001";--1
when"0010"=>datain22<="00100100";--2
when"0011"=>datain22<="00110000";--3
when"0100"=>datain22<="00011001";--4
when"0101"=>datain22<="00010010";--5
when"0110"=>datain22<="00000010";--6
when"0111"=>datain22<="01111000";--7
when"1000"=>datain22<="00000000";--8
when"1001"=>datain22<="00010000";--9
when others=>datain22<="11111111";--No signal;
end case;
end if;
end process;
process(clk_shift,reset)
variable cnt : std_logic_vector(2 downto 0);
begin
if reset='1' then
cnt:="000";
elsif clk_shift'event and clk_shift='1' then
cnt:=cnt+1;
if cnt="001" then
cs<="11";
shift<="1111";
led<="11111111"; --發光二極管、數碼管全滅;
elsif cnt="010" then
cs<="00";
shift<="1111";
led<="11111111";
elsif cnt="011" then --數碼管顯示‘0’;
cs<="01";
shift<="0111";
led<="01000000";
elsif cnt="100" then --數碼管顯示‘0’;
cs<="01";
shift<="1011";
led<="01000000";
elsif cnt="101" then --數碼管顯示datain2輸入的數據;
cs<="01";
shift<="1101";
led<=datain22;
elsif cnt="110" then --數碼管顯示datain1輸入的數據;
cs<="01";
shift<="1110";
led<=datain11;
elsif cnt="111" then --用發光二極管來代替交通燈顯示
cs<="10";
shift<="1111";
led<=data_ledfa;
end if;
end if;
end process;
end Behavioral;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -