Advertisement
Guest User

Untitled

a guest
May 21st, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.30 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. USE ieee.numeric_std.ALL;
  4.  
  5. entity RAM is
  6. port(
  7.  RAM_IN: in std_logic_vector(7 downto 0);   --wejscie
  8.  RAM_OUT: out std_logic_vector(7 downto 0);     --wyjscie
  9.  RAM_WR: in std_logic;                              --Zezwolenie
  10.  RAM_CLOCK: in std_logic;                           --zegar
  11.  RAM_ms: in std_logic_vector(3 downto 0)        --rej. RARH (clk, clr), RARL (clk, clr)
  12. );
  13. end RAM;
  14.  
  15. architecture Behavioral of RAM is
  16. -------------------------------------------------------------------------------------------
  17.     attribute RAM_style: string;                                                            --typ pamięci
  18.     type RAM_ARRAY is array (0 to 1023 ) of std_logic_vector (7 downto 0);  --definicja rozmiaru
  19.                                                                                                     --pamięci RAM 2^10=1024, 8 bit wejście/wyjście
  20.     signal RAM: RAM_ARRAY;
  21. -------------------------------------------------------------------------------------------
  22.     signal RAM_ADDR : std_logic_vector(9 downto 0);     --adres ram
  23. begin
  24.  
  25. -------------------------------------------------------------------------------------------
  26.     process(RAM_CLOCK,RAM_WR)                                               --proces zegarowy
  27.         begin
  28.             if(rising_edge(RAM_CLOCK)) then                             --jeżeli narastające zbocze zegara
  29.                    
  30.                 if(RAM_WR='1') then                                             --jeżeli RAM_WR=1
  31.                    
  32.                     RAM(to_integer(unsigned(RAM_ADDR))) <= RAM_IN;  --przypisz do pojedynczej komórki pamięci zgodnie z
  33.                                                                                     --adresem zawartość odczytaną
  34.                 end if;
  35.             RAM_OUT <= RAM(to_integer(unsigned(RAM_ADDR)));         --przypisanie wyjscia
  36.             end if;
  37.     end process;
  38. ---------------------------------------------------------------------------------------------
  39.     process(RAM_ms(1), RAM_ms(0))               --rejestr RARL
  40.         begin
  41.             if(rising_edge(RAM_ms(1))) then --zapis
  42.                 if (RAM_ms(0)='0') then
  43.                     RAM_ADDR(7 downto 0)<=RAM_IN;
  44.                 end if;
  45.             end if;
  46.            
  47.             if(RAM_ms(0)='1') then              --zerowanie
  48.                 RAM_ADDR(7 downto 0)<="00000000";
  49.             end if;
  50.     end process;
  51. ---------------------------------------------------------------------------------------------  
  52.     process(RAM_ms(2), RAM_ms(3))               --rejestr RARH
  53.         begin
  54.             if(rising_edge(RAM_ms(3))) then --zapis
  55.                 if (RAM_ms(2)='0') then
  56.                     RAM_ADDR(9 downto 8)<=RAM_IN(1 downto 0);
  57.                 end if;
  58.             end if;
  59.            
  60.             if(RAM_ms(2)='1') then              --zerowanie
  61.                 RAM_ADDR(9 downto 8)<="00";
  62.             end if;
  63.     end process;
  64. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement