Advertisement
gabrielw6

memoria_retencao.vhd

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