/////////////////////////////////////////////////////////////////////////////////////
// Author : Sidharth(DVLSI 31)
//Permission : This code only for educational purpose only
//contact :sidharth.sankar77@gmail.com
//////////////////////////////////////////////////////////////////////////////
module memory_16x4_bi(data, clk, out_en, address, rd_en, wr_en );
inout [0:3] data;
input clk;
input out_en;
input rd_en, wr_en;
input [0:3] address;
reg [0:3] memory [0:15];
reg [0:3] data_out;
assign data = out_en ? data_out : 4'bZ;
always@(posedge clk)
begin
if(rd_en)
data_out = memory[address];
else if (wr_en)
memory[address] = data;
else data_out = 4'bx;
end
endmodule
-----------------------------------------------------------------
test bench// Author : Sidharth(DVLSI 31)
//Permission : This code only for educational purpose only
//contact :sidharth.sankar77@gmail.com
//////////////////////////////////////////////////////////////////////////////
module memory_16x4_bi(data, clk, out_en, address, rd_en, wr_en );
inout [0:3] data;
input clk;
input out_en;
input rd_en, wr_en;
input [0:3] address;
reg [0:3] memory [0:15];
reg [0:3] data_out;
assign data = out_en ? data_out : 4'bZ;
always@(posedge clk)
begin
if(rd_en)
data_out = memory[address];
else if (wr_en)
memory[address] = data;
else data_out = 4'bx;
end
endmodule
-----------------------------------------------------------------
------------------------------------------------------------------
`timescale 1ns/1ps
module memory_16x4_bi_tst;
wire [0:3] data;
reg clk;
reg out_en;
reg rd_en, wr_en;
reg [0:3] address;
reg [0:3] data1;
memory_16x4_bi u1 (.data(data), .clk(clk), .out_en(out_en),.address(address), .rd_en(rd_en), .wr_en(wr_en));
assign data = !out_en ? data1 : 4'bZ;
//assign data = data1;
initial
begin
clk=1'b1;
forever #50 clk=~clk;
end
initial
begin
out_en = 1'b0;
wr_en = 1'b1;
rd_en=1'b0;
address= 4'b0000;
data1= 4'b1111;
#100;
address=4'b0001;
data1 = 4'b0110;
#100;
address=4'b0010;
data1 = 4'b0111;
#100;
out_en = 1'b1;
address= 4'b0001;
wr_en = 1'b0;
rd_en=1'b1;
#100
address=4'b0010;
#100;
out_en = 1'b0;
wr_en = 1'b1;
rd_en=1'b0;
address= 4'b0011;
data1= 4'b0011;
#100;
out_en = 1'b1;
address= 4'b0010;
wr_en = 1'b0;
rd_en=1'b1;
#100
$stop;
end
endmodule
0 comments:
Post a Comment