2024-03-04 17:16:43 +03:00
|
|
|
|
library ieee;
|
|
|
|
|
use ieee.std_logic_1164.all;
|
|
|
|
|
use ieee.std_logic_unsigned.all;
|
2024-03-04 18:16:35 +03:00
|
|
|
|
|
2024-03-26 10:23:20 +03:00
|
|
|
|
|
2024-03-14 11:27:47 +03:00
|
|
|
|
|
2024-03-26 10:23:20 +03:00
|
|
|
|
entity RAM is
|
|
|
|
|
generic(
|
|
|
|
|
DATA_BUS_WIDTH : integer := 8;
|
|
|
|
|
ADDRESS_BUS_WIDTH : integer := 9
|
|
|
|
|
);
|
2024-03-04 17:16:43 +03:00
|
|
|
|
port(
|
2024-03-26 10:23:20 +03:00
|
|
|
|
data : inout std_logic_vector(DATA_BUS_WIDTH - 1 downto 0);
|
|
|
|
|
address : in std_logic_vector(ADDRESS_BUS_WIDTH - 1 downto 0);
|
|
|
|
|
we : in std_logic;
|
|
|
|
|
oe : in std_logic;
|
|
|
|
|
ce : in std_logic
|
2024-03-04 17:16:43 +03:00
|
|
|
|
);
|
|
|
|
|
end entity;
|
|
|
|
|
|
|
|
|
|
architecture behavorial of RAM is
|
|
|
|
|
|
2024-03-26 10:23:20 +03:00
|
|
|
|
type mem is array (2**ADDRESS_BUS_WIDTH - 1 downto 0) of std_logic_vector(DATA_BUS_WIDTH - 1 downto 0);
|
|
|
|
|
signal memory : mem;
|
2024-03-04 17:16:43 +03:00
|
|
|
|
|
2024-03-26 10:23:20 +03:00
|
|
|
|
begin
|
|
|
|
|
|
|
|
|
|
process (we, oe, ce)
|
|
|
|
|
variable addr : integer range 0 to 2**ADDRESS_BUS_WIDTH - 1 := 0;
|
2024-03-04 17:16:43 +03:00
|
|
|
|
begin
|
2024-03-26 10:23:20 +03:00
|
|
|
|
if (ce = '0') then -- Если микросхема выбрана
|
|
|
|
|
addr := conv_integer(address);
|
2024-03-28 13:47:49 +03:00
|
|
|
|
if (oe = '0' and we = '1') then -- Если сигнал чтения активен, а записи нет
|
2024-03-26 10:23:20 +03:00
|
|
|
|
data <= memory(addr);
|
2024-03-28 13:47:49 +03:00
|
|
|
|
elsif (oe = '1' and we = '0') then -- Если сигнал записи активен, а чтения нет
|
|
|
|
|
memory(addr) <= data;
|
2024-03-26 10:23:20 +03:00
|
|
|
|
else
|
|
|
|
|
data <= (others => 'Z'); -- Запретить запись на шину
|
|
|
|
|
end if;
|
|
|
|
|
else
|
|
|
|
|
data <= (others => 'Z'); -- Запретить запись на шину
|
2024-03-04 17:16:43 +03:00
|
|
|
|
end if;
|
|
|
|
|
end process;
|
2024-03-14 11:27:47 +03:00
|
|
|
|
|
2024-03-04 17:16:43 +03:00
|
|
|
|
end behavorial;
|