library ieee;
use ieee.std_logic_1164.all;
entity runninglight is
port(clk,reset:in std_logic;
output:out std_logic_vector(7 downto 0));
end runninglight;
architecture behave of runninglight is
begin
signal clk1:std_logic_vector(1 downto 0);
p1:process(clk) --进程1,把50MHz分成1Hz
variable count:integer range 0 to 250000;
variable count1:integer range 0 to 1;
begin
if (clk'event and clk='1') then
count := count + 1;
if count := 250000 then
count := 0;
count1 = not count1;
end if;
clk1 <= count1;
end if;
end process
p2:process(clk1) --进程2, 把1HZ时钟计数并转换对应成移动的灯
variable count2: integer range 0 to 7;
begin
if (clk1'event and clk1='1') then
count2 := count2 + 1;
if count2 := 7 then
count2 := 0;
end if;
end if;
case count2 is
when 0 => output <= "11111110";
when 1 => output <= "11111101";
when 2 => output <= "11111011";
when 3 => output <= "11110111";
when 4 => output <= "11101111";
when 5 => output <= "11011111";
when 6 => output <= "10111111";
when 7 => output <= "01111111";
when others => z <= null;
end case;
end process;
end behave;