verilog 的代码:
module bi4b(q,dout,din,ctr1);
parameter wide = 3;
inout[wide:0] q;
input ctr1;
input[wide:0] din;
output[wide:0] dout;
wire[3:0] q,dout;
assign dout = (!ctr1) ? q : 4'bz;
assign q = (ctr1) ? din : 4'bz;
endmodule
modelsim中的测试代码:
`timescale 1 ns/ 1 ns
module test();
reg ctr1;
reg [3:0] din;
reg [3:0] q_reg;
// wires
wire [3:0] dout;
wire [3:0] q;
assign q = q_reg;
bi4b i1 (
// port map - connection between master ports and signals/registers
.ctr1(ctr1),
.din(din),
.dout(dout),
.q(q)
);
initial
begin
q_reg <= 1111;
#20 q_reg <= 0000;
#40 q_reg <= 0011;
end
initial
begin
ctr1 <= 0;
#0 din <= 1011;
#8 din <= 1001;
#13 din <= 0101;
#20 din <= 1010;
#100 $finish;
end
always
// optional sensitivity list
// @(event1 or event2 or .... eventn)
begin
#10 ctr1 <= ~ctr1;
end
endmodule
仿真 的 输入输出都 不正确 求大牛帮助
此帖出自
小平头技术问答
可以试试这种:
module bi4b(q,ctr1);
parameter wide = 4;
inout[wide-1 : 0] q;
input ctr1;
wire [wide-1 : 0] qin, qout;
assign qin = q;
assign q = (ctr1) ? qout : 4'hz;
endmodule
[ 本帖最后由 573481734 于 2011-3-20 12:19 编辑 ]
主要解决INOUT仿真测试问题!
一周热门 更多>