<p>设计一个8路彩灯显示系统,要求彩灯用两种节拍交替进行,有以下三种花型:</p><p>花型1:8路彩灯同时亮灭</p><p>花型2:8路彩灯每次只有一路灯亮,各路彩灯一次循环亮</p><p>花型3:8路彩灯每次只有4路灯亮,4路灯灭,且亮灭相间,交替亮灭</p>
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity light is
port(clk1:in std_logic;
light: buffer std_logic_vector(7 downto 0));
end light;
architecture behv of light is
constant len:integer:=7;
signal banner:std_logic;
signal clk,clk2,clk3:std_logic;
signal save:std_logic_vector(12 downto 0);
begin
clk<=(save(12)and banner)or (clk2 and not banner);
clk3<=save(12);
process(clk1)
begin
if clk1'event and clk1='1' then
save<=save+1;
end if;
end process;
process(clk3)
begin
if clk3'event and clk3='1' then
clk2<=not clk2;
end if;
end process;
process(clk)
variable flag:bit_vector(2 downto 0):="000";
begin
if clk'event and clk='1' then
if flag="000" then
light<="11111111";
if light="11111111" then
light<="00000000";
flag:="001";
light<="00000001";
end if;
elsif flag="001" then
light<=light(len-1 downto 0)&'0';
if light(7)='1' then
flag:="010";
end if;
elsif flag="010" then
light<="01010101";
if light="01010101"
then
light<="10101010";
flag:="011";
end if;
elsif flag="011" then
light<="00000000";
flag:="100";
elsif flag="100" then
banner<=not banner;
flag:="000";
else flag:="000";
end if;
end if ;
end process;
end behv;