module counter (count, clk, reset);
output [9:0] count;
input clk, reset;
reg [9:0] count;
always @ (posedge clk or posedge reset)
if (reset)
count <= 10'b0;
else
count <= count + 10'b1;
endmodule
测试文件
`timescale 10ns/1ns
module tcounter;
reg clk, reset;
wire [7:0] count;
counter dut (count, clk, reset);
initial // Clock generator
begin
clk = 0;
forever #10 clk = !clk;
end
initial
begin
reset = 0;
#5 reset = 1;
#4 reset = 0;
end
endmodule
温馨提示:答案为网友推荐,仅供参考