-------------------------------------------------------
---本例程实现一个流水灯,led灯从左至右依次点亮,并循环
-------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity one_led is
port(clk:in std_logic;
rst:in std_logic;
ledut std_logic_vector(7 downto 0)
);
end one_led;
architecture one of one_led is
signal clk10hz:std_logic;--定义10HZ时钟信号
signal led_tmp:std_logic_vector(7 downto 0);--定义8个灯的中间信号
begin
--------------------------------------------
-----------------分频器
--本进程将50MHZ时钟分频生成一个10HZ时钟1mhz=10^3khz=10^6hz
--------------------------------------------
process(clk)
variable cnt:integer range 0 to 2499999;
begin
if rising_edge(clk) then
if cnt=2499999 then
cnt:=0;
clk10hz<=not clk10hz;
else
cnt:=cnt+1;
end if;
end if;
end process;
----------------------------------------------
---本进程用信号移位的方式实现led灯的依次亮灭
----------------------------------------------
process(clk10hz,rst)
begin
if rst='0' then
led_tmp<="01111111";--led低电平点亮
elsif rising_edge(clk10hz) then
led_tmp<=led_tmp(0)&led_tmp(7 downto 1);--将led_tmp中的0右移依次循环
end if;
end process;
led<=led_tmp;
end one;