Advertisement
redsees

Digital Logic II Final Project

Dec 25th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.68 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_UNSIGNED.ALL;
  5.  
  6. entity control is
  7.    Port (
  8.         clk_in  : in   STD_LOGIC;
  9.         reset   : in   STD_LOGIC;
  10.         ot      : inout  STD_LOGIC_VECTOR (3 downto 0);
  11.         pb      : in   STD_LOGIC_VECTOR (3 downto 0);
  12.         ss0     : in   STD_LOGIC;
  13.         ss1     : in   STD_LOGIC;
  14.         leds    : inout  STD_LOGIC_VECTOR (3 downto 0);
  15.         seg     : out STD_LOGIC_VECTOR (6 downto 0)
  16.         );
  17. end control;
  18.  
  19. architecture Behavioral of control is
  20.     signal clk_out,temporal: STD_LOGIC;
  21.     signal counter : integer := 0;
  22.     type state_type is (s0,s1,s2,s3);
  23.     signal current_s,next_s: state_type;
  24.     signal lol : std_logic_vector(3 downto 0);
  25. --   signal S_led : STD_LOGIC_VECTOR (3 downto 0) := "0000";
  26. begin
  27.     frequency_divider: process (reset, clk_in) begin
  28.         if (reset = '1') then
  29.             temporal <= '0';
  30.             counter <= 0;
  31.         elsif rising_edge(clk_in) then
  32.             if (counter = 16666666) then
  33.                 temporal <= NOT(temporal);
  34.                 counter <= 0;
  35.             else
  36.                 counter <= counter + 1;
  37.             end if;
  38.         end if;
  39.     end process;
  40.    
  41.     clk_out <= temporal;
  42.    
  43.     process (clk_out,reset)
  44.      begin
  45.  
  46.         if (reset = '0') then
  47.             current_s <= next_s;
  48.         else
  49.             current_s <= s0;
  50.         end if;
  51.      end process;
  52.  
  53.     process (ss0,ss1,current_s) begin
  54.             case current_s is
  55.             when s0 =>
  56.                 if (ss1 = '0' and ss0 = '0' ) then
  57.                     ot <= "0001";
  58.                 elsif (ss1 = '0' and ss0 = '1' ) then
  59.                     ot <= "1000";
  60.                 elsif (ss1 = '1' and ss0 = '0' ) then
  61.                     ot <= "0001";
  62.                 elsif (ss1 = '1' and ss0 = '1' ) then
  63.                     ot <= "0001";
  64.                 end if;
  65.                 next_s <= s1;
  66.             when s1 =>
  67.                 if (ss1 = '0' and ss0 = '0' ) then
  68.                     ot <= "0010";
  69.                 elsif (ss1 = '0' and ss0 = '1' ) then
  70.                     ot <= "0100";
  71.                 elsif (ss1 = '1' and ss0 = '0' ) then
  72.                     ot <= "0100";
  73.                 elsif (ss1 = '1' and ss0 = '1' ) then
  74.                     ot <= "1000";
  75.                 end if;
  76.                 next_s <= s2;
  77.             when s2 =>
  78.                 if (ss1 = '0' and ss0 = '0' ) then
  79.                     ot <= "0100";
  80.                 elsif (ss1 = '0' and ss0 = '1' ) then
  81.                     ot <= "0010";
  82.                 elsif (ss1 = '1' and ss0 = '0' ) then
  83.                     ot <= "0010";
  84.                 elsif (ss1 = '1' and ss0 = '1' ) then
  85.                     ot <= "0010";
  86.                 end if;
  87.                 next_s <= s3;
  88.             when s3 =>
  89.                 if (ss1 = '0' and ss0 = '0' ) then
  90.                     ot <= "1000";
  91.                 elsif (ss1 = '0' and ss0 = '1' ) then
  92.                     ot <= "0001";
  93.                 elsif (ss1 = '1' and ss0 = '0' ) then
  94.                     ot <= "1000";
  95.                 elsif (ss1 = '1' and ss0 = '1' ) then
  96.                     ot <= "0100";
  97.                 end if;
  98.                 next_s <= s0;
  99.             end case;
  100.     end process;
  101.     process (pb,ot,leds)
  102.     begin
  103.         while (pb = "0000") loop
  104.         end loop;
  105.         lol <= pb AND ot;
  106.         if ( (lol = "1000") or (lol = "0100") or (lol = "0010") or (lol = "0001")) then
  107.             leds <= leds + "1";
  108.         end if;
  109.     end process;
  110.     process (leds)
  111.     begin
  112.         case leds is
  113.              when "0000"=>seg<="0000001"; -- '0'
  114.              when "0001"=>seg<="1111001"; -- '1'
  115.              when "0010"=>seg<="0100100"; -- '2'
  116.              when "0011"=>seg<="0110000"; -- '3'
  117.              when "0100"=>seg<="0011001"; -- '4'
  118.              when "0101"=>seg<="0010010"; -- '5'
  119.              when "0110"=>seg<="0000010"; -- '6'
  120.              when "0111"=>seg<="1111000"; -- '7'
  121.              when "1000"=>seg<="0000000"; -- '8'
  122.              when "1001"=>seg<="0010000"; -- '9'
  123.              when "1010"=>seg<="0100000"; -- 'A'
  124.              when "1011"=>seg<="0000011"; -- 'B'
  125.              when "1100"=>seg<="1000110"; -- 'C'
  126.              when "1101"=>seg<="0100001"; -- 'D'
  127.              when "1110"=>seg<="0000100"; -- 'E'
  128.              when "1111"=>seg<="0001110"; -- 'F'
  129.              when others=>seg<="1111111"; -- 'NULL'
  130.         end case;
  131.     end process;
  132. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement