Decade counter again

Make a decade counter that counts 1 through 10, inclusive. The reset input is synchronous, and should reset the counter to 1.
题目

题目网站

 1 module top_module (
 2     input clk,
 3     input reset,
 4     output [3:0] q);
 5 always @(posedge clk)begin
 6     if(reset || q>=4'd10)begin   //为什么这里是4'd10?哦,因为这里直接使用d十进制,但是注意是4位
 7         //来表示,上一题也一样,用的是十进制9
 8             q<=4'b1;
 9         end
10         else begin
11             q<=q+1'b1;
12         end
13     end
14 
15 endmodule
posted @ 2024-04-10 02:04  江左子固  阅读(17)  评论(0编辑  收藏  举报