Guest User

Untitled

a guest
May 27th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.02 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use ieee.numeric_std.ALL;
  4. use ieee.std_logic_arith.all;
  5.  
  6. entity memorie8x4 is
  7.     port(
  8.    
  9.     clk:        in std_logic;
  10.     cs:     in std_logic; -- cs = 1 => chip selected
  11.     rw:     in std_logic; -- rw = 1 => read; 0 => write
  12.     address: in std_logic_vector(2 downto 0);
  13.     output:     inout std_logic_vector(3 downto 0) -- tip inout ca sa putem si citi si scrie
  14.    
  15.     );
  16. end memorie8x4;
  17.  
  18. architecture Behavioral of memorie8x4 is
  19.  
  20.     type MEM_array is array(0 to 7) -- 3 biti de adresa
  21.         of std_logic_vector(3 downto 0);
  22.     signal mem8x4: MEM_array := (others => "0000"); -- valorile noastre prestabilite
  23.    
  24.     signal out_sig: std_logic_vector(3 downto 0) := "ZZZZ";
  25. begin
  26.     -- este output doar cand suntem in read mode. Cand suntem in write mode e input
  27.     -- ( starea Z e impedanta mare ca sa putem citi valori de la portul output )
  28.     output <= out_sig when (cs = '1' and rw = '1') else (others => 'Z');
  29.  
  30.     process(clk, cs, rw, address)
  31.     begin
  32.     if rising_edge(clk) then
  33.         if cs = '0' then
  34.             out_sig <= "ZZZZ";
  35.         else -- chip-ul este selectat
  36.             if rw = '1' then --modul read a fost selectat
  37.                 case address is
  38.                     when "000" => out_sig <= mem8x4(0);
  39.                     when "001" => out_sig <= mem8x4(1);
  40.                     when "010" => out_sig <= mem8x4(2);
  41.                     when "011" => out_sig <= mem8x4(3);
  42.                     when "100" => out_sig <= mem8x4(4);
  43.                     when "101" => out_sig <= mem8x4(5);
  44.                     when "110" => out_sig <= mem8x4(6);
  45.                     when "111" => out_sig <= mem8x4(7);
  46.                     when others => out_sig <= "0000";
  47.                 end case;
  48.             else -- modul write a fost selectat
  49.                 case address is
  50.                     when "000" => mem8x4(0) <= output;
  51.                     when "001" => mem8x4(1) <= output;
  52.                     when "010" => mem8x4(2) <= output;
  53.                     when "011" => mem8x4(3) <= output;
  54.                     when "100" => mem8x4(4) <= output;
  55.                     when "101" => mem8x4(5) <= output;
  56.                     when "110" => mem8x4(6) <= output;
  57.                     when "111" => mem8x4(7) <= output;
  58.                     when others => mem8x4 <= (others => "0000");
  59.                 end case;
  60.             end if;
  61.         end if;
  62.     end if;    
  63.     end process;
  64.  
  65. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment