實驗現象:
核心程式碼:
module single_port_ram( input CLK_12M, input WR, input RD, input CS0, inout [15:0]DB, input [24:16]A, output FPGA_LEDR, output FPGA_LEDG, output FPGA_LEDB ); //----------------------------pll-------------------------------// /*例項化MY_PLL模組,輸出48M時鐘*/ my_pll u1( .inclk0(CLK_12M), .c0(PLL_48M) ); //---------------------------rst_n----------------------------// /*復位訊號,10個週期後rst_n置1*/ reg [3:0]cnt_rst=4'd0; reg rst_n; always@(posedge CLK_12M) begin if(cnt_rst==4'd10) begin rst_n <= 1'd1; cnt_rst <= 4'd10; end else cnt_rst <= cnt_rst + 1'd1; end //-------------------------fsmc-----------------------------// wire rd =(CS0|RD);// 提取讀訊號 wire wr =(CS0|WR);// 提取寫訊號 reg wr_clk1,wr_clk2; always@(posedge PLL_48M or negedge rst_n) begin if(!rst_n) begin wr_clk1 <= 1'd1; wr_clk2 <= 1'd1; end else {wr_clk2,wr_clk1} <= {wr_clk1,wr}; end wire clk = (!wr_clk2|!rd); //將讀寫訊號轉化為時鐘訊號 assign DB = !rd?DB_OUT :16'hzzzz; //---------------------------ram-------------------------------// /*例項化ram塊*/ wire [15:0]DB_OUT; my_ram u2( .address(A), .clock(clk), .data(DB), .wren(!wr), .rden(!rd), .q(DB_OUT) ); //--------------------------led----------------------------// assign FPGA_LEDR = 1'd1; assign FPGA_LEDG = 1'd0; assign FPGA_LEDB = 1'd1; //-----------------------endmodule-------------------------// endmodule
實驗方法及指導書:
連結:http://pan.baidu.com/s/1jIBXsSu 密碼:38q7