Advertisement
gabrielw6

memoria_retencao.vhd

May 21st, 2019
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.94 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  4. use IEEE.NUMERIC_STD.ALL;
  5.  
  6. entity memoria_retencao is
  7.     Port ( clk : in STD_LOGIC;
  8.            reset : in STD_LOGIC;
  9.            lib : in STD_LOGIC;
  10.            btnU, btnL, btnC, btnR : in STD_LOGIC;
  11.            sol : out STD_LOGIC;
  12.            state : out STD_LOGIC_VECTOR (3 downto 0);
  13.            ad : out STD_LOGIC_VECTOR (3 downto 0));
  14. end memoria_retencao;
  15.  
  16. architecture Behavioral of memoria_retencao is
  17.     signal reg, buf: STD_LOGIC_VECTOR (3 downto 0);
  18.     signal ad_sig : STD_LOGIC_VECTOR (3 downto 0);
  19.     signal count : unsigned (1 downto 0);
  20. begin
  21.     buf(0) <= btnR;
  22.     buf(1) <= btnC;
  23.     buf(2) <= btnL;
  24.     buf(3) <= btnU;
  25.     ad <= ad_sig;
  26.     state <= reg;
  27.     armazena: process(clk, reset)
  28.     begin
  29.         if reset = '1' then
  30.             reg <= (others => '0');
  31.         elsif rising_edge(clk) then
  32.             for i in 3 downto 0 loop
  33.                 if buf(i) = '1' then
  34.                     reg(i) <= '1';
  35.                 end if;
  36.             end loop;
  37.            
  38.             if lib = '1' then
  39.                 reg <= reg and (not ad_sig); -- mascara para zerar o andar
  40.             end if;
  41.         end if;
  42.     end process;
  43.    
  44.     algoritmob: process(clk, reset)
  45.     begin
  46.         if reset = '1' then
  47.             ad_sig <= (others => '0');
  48.             count <= "00";
  49.         elsif rising_edge(clk) then
  50.             if reg(to_integer(count)) = '1' then
  51.                 ad_sig(to_integer(count)) <= '1';
  52.                 ad_sig(to_integer(count+"01")) <= '0';
  53.                 ad_sig(to_integer(count+"10")) <= '0';
  54.                 ad_sig(to_integer(count+"11")) <= '0';
  55.             else
  56.                 count <= count + 1;
  57.             end if;
  58.            
  59.             if reg > 0 then
  60.                 sol <= '1';
  61.             else
  62.                 sol <= '0';
  63.             end if;
  64.         end if;
  65.     end process;
  66.  
  67.  
  68. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement