Advertisement
redsees

Untitled

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