16 字节的 RAM 设计

上一篇 / 下一篇  2007-12-11 19:22:32 / 个人分类:示例代码

简单 RAM 代码示例
--  16 字节的 RAM 设计
--  VHDL 语言与FPGA 设计- 基于PROTEL dxp开发平台  p348
library ieee;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ram16x8 is
port(clk  : in std_logic;   
address : in std_logic_vector(3 downto 0); -- 16=2**4
csbar,oebar,webar :in std_logic;
data : inout std_logic_vector(7 downto 0));
end ram16x8;
--------------------------------------------------
architecture rtl of ram16x8 is
begin
process(address,csbar,oebar,webar,data,clk)
  type ram_array is array (0 to 15) of bit_vector(7 downto 0);
  variable index:integer := 0;
  variable ram_store : ram_array;  -- 定义一个存储体
begin
  if clk'event and clk='1' then
   if csbar='0' then
    index := 0;  -- 计算地址(整数),一定为变量
    for i in address'range loop -- for i in 0 to 15 loop
     if address(i)='1' then
      index := index+2**i;
     end if;
    end loop;
   end if;
   if webar='1' then
    -- 当'写'脉冲的上升沿到来的时才能进行写RAM操作
    ram_store(index) := to_bitvector(data);
   elsif ebar='0' then
    data <= to_stdlogicvector(ram_store(index));
   else
    data <= (others=>'Z');
   end if;
  end if;
end process;

end rtl;

TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2009-01-07  
    123
45678910
11121314151617
18192021222324
25262728293031

数据统计

  • 访问量: 856
  • 日志数: 7
  • 文件数: 1
  • 建立时间: 2007-03-16
  • 更新时间: 2007-12-16

RSS订阅

Open Toolbar