动态扫描
模块说明:通过一个分频器输出的100hz的计数信号,不断对count3信号进行00 01 10 11的循环,每个数字代表要显示不同的显示管,然后判断白天黑夜状态量,如果是白天,就取白天模块的四个输出作为显示管要显示的数,如果是黑夜,则要判断中间信号strobe,如果信号为‘0’代表没有人按键,四个显示管显示黑夜模式的四个输出,如果中间信号为‘1’代表有人按键,则四个显示管显示黑夜模式2的四个输出,同时动态扫描集成了译码电路,将十进制数转译成8位电平的高低来控制显示管
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY dongtaisaomiao IS
PORT ( CLK : IN STD_LOGIC; -----
data_out : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
NUM0,NUM1,NUM2,NUM3 : inout STD_LOGIC_VECTOR(3 DOWNTO 0);-------
count_day:in std_logic;
strobe: in std_logic;
enable: in std_logic;
xianshiguan : OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
END ENTITY dongtaisaomiao;
ARCHITECTURE behav OF dongtaisaomiao IS
SIGNAL count3 :STD_LOGIC_VECTOR(1 DOWNTO 0); ----
SIGNAL bcd_in: STD_LOGIC_VECTOR(3 DOWNTO 0); ---
SIGNAL NUM01,NUM11,NUM21,NUM31 : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL NUM02,NUM12,NUM22,NUM32 : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL NUM00,NUM10,NUM20,NUM30 : STD_LOGIC_VECTOR(3 DOWNTO 0);
BEGIN
P1: PROCESS(count3) ----
BEGIN
CASE count3 IS
WHEN "00"=>xianshiguan<="1110"; -----
WHEN "01"=>xianshiguan<="1101";
WHEN "10"=>xianshiguan<="1011";
WHEN "11"=>xianshiguan<="0111";
WHEN OTHERS => NULL;
END CASE;
END PROCESS P1;
P2: PROCESS(CLK) ----count3
BEGIN
IF CLK'EVENT AND CLK ='1'
THEN count3 <= count3+1;
END IF;
END PROCESS P2;
P3: PROCESS(clk)
BEGIN
if enable'event and enable='1' then
if count_day= '1' then
if strobe= '1' then
num0 <= num00;
num0 <= num10;
num0 <= num20;
num0 <= num30;
IF (count3="00") THEN bcd_in <= num0; ----
ELSIF (count3="01") THEN bcd_in <= num1;
ELSIF (count3="10") THEN bcd_in <= num2;
ELSIF (count3="11") THEN bcd_in <= num3;
END IF;
end if;
end if;
end if;
if enable'event and enable='1' then
if count_day= '1' then
if strobe= '0' then
num0 <= num01;
num0 <= num11;
num0 <= num21;
num0 <= num31;
elsif count_day= '0' then
num0 <= num02;
num0 <= num12;
num0 <= num22;
num0 <= num32;
IF (count3="00") THEN bcd_in <= num0; ----
ELSIF (count3="01") THEN bcd_in <= num2;
ELSIF (count3="10") THEN bcd_in <= num2;
ELSIF (count3="11") THEN bcd_in <= num3;
END IF;
end if;
end if;
end if;
CASE bcd_in IS
when "0000" => data_out <= "11000000"; -- 0 -----
when "0001" => data_out <= "11111001"; -- 1
when "0010" => data_out <= "10100100"; -- 2
when "0011" => data_out <= "10110000"; -- 3
when "0100" => data_out <= "10011001"; -- 4
when "0101" => data_out <= "10010010"; -- 5
when "0110" => data_out <= "10000010"; -- 6
when "0111" => data_out <= "11111000"; -- 7
when "1000" => data_out <= "10000000"; -- 8
when "1001" => data_out <= "10010000"; -- 9
WHEN OTHERS => NULL;
END CASE;
END PROCESS P3;
END behav;