verilog hdl 设计一下降沿触发,带低电平置位的触发器。 编写测试文件并仿真

2024-11-20 11:37:43
推荐回答(1个)
回答(1):

//DFF code
module dff(q, rst, clk, d);
output q;
input clk,rst;
input d;
reg q;
always @(negedge clk)
if(~rst)
q <= 1'b0;
else
q <= d;

endmodule

//testbench
module tb;
reg clk,rst,d;
wire q;
initial begin
clk = 1'b0;
rst = 1'b1;
d = 1'b0;
#10 rst= 1'b0;
#20 rst =1'b1;

#10 d = 1'b1;

#20 d = 1'b0;
#30 d = 1'b1;
#10 d = 1'b0;
end
always
#5 clk = ~clk;

dff x1(q, rst, clk, d);
endmodule