我编写了一个5*8的存储器,代码如下:library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity ram is
port(clk,wr,rd,en,reset:in std_logic;
addr:in std_logic_vector(4 downto 0);
wr_add:in std_logic_vector(4 downto 0);
din:in std_logic_vector(7 downto 0);
dout: out std_logic_vector(7 downto 0));
end ram;
architecture beh of ram is
type vector_memory is array(31 downto 0)of std_logic_vector(7 downto 0);
signal memory:vector_memory;
signal add:integer range 0 to 31;
begin
add<=conv_integer(wr_add);
p1:process(clk,wr,en,add,reset)
begin
if wr='1'and en='1' and reset='1'then
if clk'event and clk='1' then
memory(add)<=din;
end if;
elsif reset='0' then
memory(add)<="00000000";
end if;
end process p1;
p2:process(clk,rd,en,addr,memory,reset)
variable add_rd:integer range 0 to 31;
begin
add_rd:=conv_integer(addr);
if rd='1'and en='1' and reset='1' then
if clk='1' then
dout<=memory(add_rd);
else
dout<="ZZZZZZZZ";
end if;
end if;
end process p2;
end architecture; 但是仿真波形有点不对,在地址0写的数据,读出数据时,在地址0的数据时地址1存储的数据,以后的数据都是这样,请各位大侠指教。 不能粘贴波形呀,本来想把仿真波形放上的
此帖出自
小平头技术问答
一周热门 更多>