本人小白,希望有贵人能指点下
counter.v
module counter( //Module naming
input clk, //Declarations of input and output variables.
input reset,
output reg [7:0] count
);
/It also includes the definition of parameters
and declarations of other variables used in the file./
always@(posedge clk) //Function realization code.
begin
~~if (count===8'bxxxxxxxx)count=8'b0000_0000;~~
if(!reset) count<=8'b0000_0000;
else if(count==8'b1111_1111) count<=8'b0000_0000;
else count<=count+1;
end
endmodule
counter_tb.v
`timescale 1ns/1ns //Time unit/time precision.
module counter_tb; //Testbench module name, usually named after this file.
parameter T=20; //parameter definition
reg clk; //input
reg reset;
wire [7:0]count; //output
initial //Signal initialization, all input signals, such as clock and reset signal.
begin
clk=1'b0;
reset=1'b0;
#(T/2)
reset=1'b1;
end
always #(T/2) clk=~clk;//Generate a clock to simulate the actual cycle timing of the crystal oscillator.
counter u_counter( //instantiate the module to be tested.
.clk (clk), //Note that the statement is followed by a comma.
.reset (reset), //There is no comma in the last step.
.count (count)
);
endmodule
更多回帖