20180721:
testbench模板1:
*******************************************
1.代码文件:
//module KEY_AND_LED ( clk, rst_n, key_in, led );
module KEY_AND_LED ( clk, rst_n, led );
input clk,rst_n;
output reg [3:0]led;
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
led<=4'b0111;
else
led<={led[2:0],led[3]};
end
//assign F = A & B;
endmodule
2.testbench文件:
`timescale 1ns/1ns
module KEY_AND_LED_tb;
reg clk,rst_n;
wire [3:0] led;
always #10 clk=~clk;
initial
begin
clk=0;
rst_n=0;
#100 rst_n=1;
#1000 $stop;
end
KEY_AND_LED KEY_AND_LED_tb(
.clk(clk),
.rst_n(rst_n),
.led(led));
endmodule
testbench模板2:
*******************************************
1.代码文件:
module KEY_AND_LED ( clk, rst_n, key_in, pio_led );
input clk,rst_n,key_in;
output reg pio_led ;
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
pio_led<=1;
else
if(!key_in)
pio_led<=0;
end
endmodule
2.testbench文件:
`timescale 1ns/1ns
module KEY_AND_LED_tb;
reg clk,rst_n,key_in;
wire pio_led;
always #10 clk=~clk;
initial
begin
clk=0;
rst_n=0;
key_in=1;
#1000 rst_n=1;
# 200 key_in=0;
# 400 key_in=1;
// #10 $stop;
end
KEY_AND_LED KEY_AND_LED_tb(
.clk(clk),
.rst_n(rst_n),
.key_in(key_in),
.pio_led(pio_led));
endmodule
*******************************************
testbench模板3:
//***********************************
module KEY_AND_LED( a, b, c, sel1,sel2,out );
input a, b, c, sel1,sel2;
output reg out;
always @( * )
begin
if(sel1==1)
out<=a;
else if(sel2==1)
out<=b;
else
out<=c;
end
//assign F = A & B;
endmodule
//***testbench*****
`timescale 1ns/1ps
module KEY_AND_LED_tb;
reg a, b, c, sel1,sel2;
wire out;
initial
begin
a=0;
b=0;
c=1;
sel1=0;
sel2=0;
#30 sel1=1;
#30 sel2=1;
#100 sel2=0; // add a $stop or $finish is a good idea;
end
KEY_AND_LED KEY_AND_LED_tb(
.a(a),
.b( b),
.c(c),
.sel1(sel1),
.sel2(sel2),
.out(out)
);
endmodule
*******************************************