45 lines
1.2 KiB
VHDL
45 lines
1.2 KiB
VHDL
library ieee;
|
|
use ieee.std_logic_1164.all;
|
|
use ieee.std_logic_unsigned.all;
|
|
|
|
|
|
|
|
entity RAM is
|
|
generic(
|
|
DATA_BUS_WIDTH : integer := 8;
|
|
ADDRESS_BUS_WIDTH : integer := 9
|
|
);
|
|
port(
|
|
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
|
|
);
|
|
end entity;
|
|
|
|
architecture behavorial of RAM is
|
|
|
|
type mem is array (2**ADDRESS_BUS_WIDTH - 1 downto 0) of std_logic_vector(DATA_BUS_WIDTH - 1 downto 0);
|
|
signal memory : mem;
|
|
|
|
begin
|
|
|
|
process (we, oe, ce)
|
|
variable addr : integer range 0 to 2**ADDRESS_BUS_WIDTH - 1 := 0;
|
|
begin
|
|
if (ce = '0') then -- Если микросхема выбрана
|
|
addr := conv_integer(address);
|
|
if (oe = '0') then -- Если сигнал чтения активен
|
|
data <= memory(addr);
|
|
elsif (we = '0') then -- Если сигнал записи активен
|
|
memory(addr) <= data;
|
|
else
|
|
data <= (others => 'Z'); -- Запретить запись на шину
|
|
end if;
|
|
else
|
|
data <= (others => 'Z'); -- Запретить запись на шину
|
|
end if;
|
|
end process;
|
|
|
|
end behavorial; |