Advertisement
LucaSkywalker

TrafficLight.vhd

Nov 7th, 2020
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.54 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.std_logic_1164.all;
  3. use IEEE.std_logic_arith.all;
  4. use IEEE.std_logic_misc.all;
  5. use IEEE.std_logic_unsigned.all;
  6.  
  7. entity TrafficLight is
  8.     Port (  E:      IN      STD_LOGIC;
  9.                 N:  IN      STD_LOGIC;
  10.                 Rst:    IN      STD_LOGIC;
  11.                 Clk:    IN      STD_LOGIC;
  12.                 R:  OUT     STD_LOGIC;
  13.                 Y:  OUT     STD_LOGIC;
  14.                 G:  OUT     STD_LOGIC);
  15. end TrafficLight;
  16. architecture Behavioral of TrafficLight is
  17.     signal State : STD_LOGIC_VECTOR(2 DOWNTO 0) := "000";
  18.     begin
  19.     Main: process(Clk, Rst)
  20.         begin
  21.         if Rst = '1' then
  22.             State <= "000";
  23.             R <= '0';
  24.             Y <= '0';
  25.             G <= '0';
  26.         elsif Rising_Edge(CLK) then
  27.             case State is
  28.                 when "000" =>
  29.                     State <= "001";
  30.                     R <= '0';
  31.                     Y <= '0';
  32.                     G <= '1';
  33.                 when "001" =>
  34.                     R <= '0';
  35.                     Y <= '0';
  36.                     G <= '1';
  37.                     if E = '1' then
  38.                         State <= "010";
  39.                     else
  40.                         State <= "011";
  41.                     end if;
  42.                 when "010" =>
  43.                     State <= "011";
  44.                     R <= '0';
  45.                     Y <= '0';
  46.                     G <= '1';
  47.                 when "011" =>
  48.                     State <= "100";
  49.                     R <= '0';
  50.                     Y <= '1';
  51.                     G <= '0';
  52.                 when "100" =>
  53.                     State <= "101";
  54.                     R <= '1';
  55.                     Y <= '0';
  56.                     G <= '0';
  57.                 when "101" =>
  58.                     R <= '1';
  59.                     Y <= '0';
  60.                     G <= '0';
  61.                     if N = '1' then
  62.                         State <= "110";
  63.                     else
  64.                         State <= "111";
  65.                     end if;
  66.                 when "110" =>
  67.                     State <= "111";
  68.                     R <= '1';
  69.                     Y <= '0';
  70.                     G <= '0';
  71.                 when "111" =>
  72.                     State <= "000";
  73.                     R <= '1';
  74.                     Y <= '1';
  75.                     G <= '0';
  76.                 when others =>
  77.             end case;
  78.         end if;
  79.     end process Main;
  80. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement