Advertisement
Guest User

Untitled

a guest
May 19th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.89 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.     signal espera : STD_LOGIC;
  20. begin
  21.     armazena: process(clk, reset)
  22.     begin
  23.         if reset = '1' then
  24.             reg <= (others => '0');
  25.         elsif rising_edge(clk) then
  26.             for i in 3 downto 0 loop
  27.                 if buf(i) = '1' then
  28.                     reg(i) <= '1';
  29.                 end if;
  30.             end loop;
  31.            
  32.             if lib = '1' then
  33.                 reg <= reg and (not ad_sig); -- mascara para zerar o andar
  34.             end if;
  35.         end if;
  36.     end process;
  37.     inc: process(clk, reset)
  38.     begin
  39.         if reset = '1' then
  40.             count <= "00";
  41.         elsif rising_edge(clk) then
  42.             if espera = '0' then
  43.                 count <= count + 1;
  44.             end if;
  45.         end if;
  46.     end process;
  47.    
  48.     algoritmob: process(clk, reset)
  49.     begin
  50.         if reset = '1' then
  51.            
  52.         elsif rising_edge(clk) then
  53.             if reg(to_integer(count)) = '1' then
  54.                 ad_sig(to_integer(count)) <= '1';
  55.                 ad_sig(to_integer(count)+1) <= '0';
  56.                 ad_sig(to_integer(count)+2) <= '0';
  57.                 ad_sig(to_integer(count)+3) <= '0';
  58.                 espera <= '1';
  59.             else
  60.                 espera <= '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