Você está na página 1de 3

Tarefa: Faça um circuito que acenda um LED por vez, do LED0 ao LED9 e

depois retorne do LED9 ao LED0

■ Inclua as seguintes funcionalidades nas chaves e/ou botões:


– Resetar o circuito
– Desabilitar (pausar) o circuito

Código:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity atividade5 is
generic (
f_clk: integer := 15_000_000 -- Frequência do clock
);

port (
clk: in std_logic; -- Entrada do clock
enable: in std_logic; -- Botão de habilitar
reset: in std_logic; -- Botão de reset
pause: in std_logic; -- Botão de pausa
leds: out std_logic_vector(9 downto 0) -- Saída dos LEDs de 10 bits
);
end entity atividade5;

architecture atividade5 of atividade5 is


constant tempo_piscar: integer := f_clk / 10; -- Definição da constante para determinar o
tempo de piscar

signal contador: integer range 0 to f_clk'high := 0; -- Contador para medir o tempo


signal indice_led: integer range 0 to 9 := 0; -- Índice do LED atual
signal leds_temp: std_logic_vector(9 downto 0) := (others => '0'); -- Armazena o estado
dos LEDs temporariamente
signal direcao: std_logic := '0'; -- Sinal para a direção ('0' para avançar, '1' para
retroceder)
signal tempo_led: integer := 0; -- Tempo que o LED atual permanece aceso

begin
-- Processo de controle de LEDs
process (clk, reset, enable, pause)
begin
if reset = '0' then
-- Quando o botão de reset é pressionado, redefina as variáveis
contador <= 0;
indice_led <= 0;
leds_temp <= (others => '0');
direcao <= '0';
tempo_led <= 0;
elsif rising_edge(clk) and enable = '1' then
-- Somente se o botão de habilitar estiver pressionado
if pause = '0' then
-- Se não estiver pausado
if contador = tempo_piscar then
contador <= 0;
leds_temp <= (others => '0');
leds_temp(indice_led) <= '1';

if direcao = '0' then


indice_led <= indice_led + 1;
if indice_led = 9 then
direcao <= '1'; -- Inverte a direção quando atinge o LED9
end if;
else
indice_led <= indice_led - 1;
if indice_led = 0 then
direcao <= '0'; -- Inverte a direção quando atinge o LED0
end if;
end if;
else
contador <= contador + 1;
end if;
else
-- Se estiver pausado
if tempo_led = tempo_piscar then
tempo_led <= 0;
leds_temp <= (others => '0');
leds_temp(indice_led) <= '1';
else
tempo_led <= tempo_led + 1;
end if;
end if;
end if;
end process;

leds <= leds_temp; -- Atualiza as saídas dos LEDs com o valor temporário
end architecture atividade5;

Você também pode gostar