用NIOS II在DE2-70开发板上测试SDRAM,本文是将拨动开关的值先存储到SDRAM中,然后再从SDRAM中读出来,并用LED显示。
SOPC框图如下:
1.JPG
verilog源代码如下:
/*
write by C http://www.liuhelu.cn
data:2010.1.3
*/
module sdramtest(iSW,iKEY,iCLK_50,oLEDG,oDRAM0_CLK,
oDRAM0_CKE,oDRAM0_A,oDRAM0_BA,oDRAM0_CS_N,oDRAM0_CAS_N,
oDRAM0_RAS_N,oDRAM0_WE_N,DRAM_DQ,oDRAM0_LDQM0,oDRAM0_UDQM1
);
input [7:0] iSW;
input [0:0] iKEY;
input iCLK_50;
output [7:0] oLEDG;
output [12:0] oDRAM0_A;
output oDRAM0_CLK,oDRAM0_CKE,oDRAM0_CS_N,oDRAM0_CAS_N,oDRAM0_RAS_N,oDRAM0_WE_N,oDRAM0_LDQM0,oDRAM0_UDQM1;
output [1:0] oDRAM0_BA;
inout [15:0] DRAM_DQ;
nios niosiisystem( //SOPC
// 1) global signals:
.clk_0(iCLK_50),
.reset_n(iKEY),
// the_ledg
.out_port_from_the_ledg(oLEDG),
// the_sdram
.zs_addr_from_the_sdram(oDRAM0_A),
.zs_ba_from_the_sdram(oDRAM0_BA),
.zs_cas_n_from_the_sdram(oDRAM0_CAS_N),
.zs_cke_from_the_sdram(oDRAM0_CKE),
.zs_cs_n_from_the_sdram(oDRAM0_CS_N),
.zs_dq_to_and_from_the_sdram(DRAM_DQ),
.zs_dqm_from_the_sdram({oDRAM0_UDQM1,oDRAM0_LDQM0}),
.zs_ras_n_from_the_sdram(oDRAM0_RAS_N),
.zs_we_n_from_the_sdram(oDRAM0_WE_N),
// the_switchws
.in_port_to_the_switchws(iSW)
);
sdram_pll u2 ( //PLL
.inclk0(iCLK_50),
.c0(oDRAM0_CLK));
endmodule
C语言代码程序:
#include "system.h"
#include <io.h>
int main(){
while(1){
unsigned int i=IORD(SWITCHWS_BASE,0); //READ SWITCHWS
unsigned int j=0;
IOWR(SDRAM_BASE,0,i); //WRITE SDRAM
j=IORD(SDRAM_BASE,0);//READ SDRAM
IOWR(LEDG_BASE,0,j);//WRITE LEDG_BASE
}
}
本文出自http://www.liuhelu.cn/article/cf/1024.html |