You are on page 1of 3

--Hola esto es el programa que encontre, el cual use para hacer el semaforo

---Semforos 1 y 2
library ieee;
use ieee.std_logic_1164.all;
use work.std_arith.all;
entity semaforo is port(
clk,p: in std_logic; --clk=clok y p-> es una habilitacion
d: out std_logic_vector(5 downto 0));-- Son las salidas de los leds de los
dos semaforos
-- comenzando semaforo 1-->d5,d4,d3
-- semaforo 2 -->d2,d1,d0
end semaforo;
architecture a_semaf of semaforo is
signal q:std_logic_vector (3 downto 0);
begin
process (clk) begin
if (clk'event and clk='1')then
q <= q+1;
if (q="1111") then
q<="0000";
end if;
end if;
end process;
process (q) begin
case q is

when "0000"=>
if p='0' then -- si p='0' entonces parpadeo de semforos
esta desactivado
d<="001100"; --Salidas de los leds, de izquierda a derecha
los primers tres bits son el semaforo 1
--los ultimos bits son del semaforo derecho
-- d5,d4,d3 son Semaforo 1
-- d2,d2,d1 son semaforo 2
elsif p='1' then -- si p='1' entonces parpadeo esta activado
y los semaforos
-- van a prender rojo y amarillo
d<="010010"; -- en este caso
d5=rojo(apagado),d4=amarillo(encendido), d3=verde(apagado) -->Semaforo 1
--
d2=rojo(apagado),d1=amarillo(encendido),d0=verde(apagado)----->semaforo 2
end if;
when "0001"=>
if p='0' then
d<="001100";
elsif p='1' then
d<="100100";
end if;
when "0010"=>
if p='0' then
d<="001100";
elsif p='1' then
d<="010010";
end if;
when "0011"=>
if p='0' then
d<="001100";
elsif p='1' then
d<="100100";
end if;
when "0100"=>
if p='0' then
d<="010100";
elsif p='1' then
d<="010010";
end if;
when "0101"=>
if p='0' then
d<="000100";
elsif p='1' then
d<="100100";
end if;
when "0110"=>
if P='0' then
d<="010100";
elsif P='1' then
d<="010010";
end if;
when "0111"=>
if P='0' then
d<="000100";
elsif P='1' then
d<="100100";
end if;
when "1000"=>
if P='0' then
d<="100001";
elsif P='1' then
d<="010010";
end if;
when "1001"=>
if P='0' then
d<="100001";
elsif P='1' then
d<="100100";
end if;
when "1010"=>
if P='0' then
d<="100001";
elsif P='1' then
d<="010010";
end if;
when "1011"=>
if P='0' then
d<="100001";
elsif P='1' then
d<="100100";
end if;
when "1100"=>
if P='0' then
d<="100010";
elsif P='1' then
d<="010010";
end if;
when "1101"=>
if P='0' then
d<="100000";
elsif P='1' then
d<="100100";
end if;
when "1110"=>
if P='0' then
d<="100010";
elsif P='1' then
d<="010010";
end if;
when others=>
if P='0' then
d<="100000";
elsif P='1' then
d<="100100";
end if;
end case;
end process;
end a_semaf;

You might also like