题解 | #简易秒表#

简易秒表

https://www.nowcoder.com/practice/6493ca8c7b67499f918e1fa33b4cdeda

module count_module(
	input clk,
	input rst_n,

    output reg [5:0]second,
    output reg [5:0]minute
	);
always @ (posedge clk or negedge rst_n )
begin
if(!rst_n)
begin
second<=6'd0;
end
else
begin
second<= second==6'd60 ? 6'd1: second+6'd1;
end
end	

always @ (posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
minute<=6'd0;
end
else
begin
if(second==6'd60)
begin
minute<= minute==6'd60 ? 6'd1: minute+6'd1;
end
else
begin
minute<= minute;
end
end
end
endmodule

`timescale 1ns/1ns
module testbench();
    reg rst;
	reg clk=1;
	wire[5:0] second,minute;
	 count_module u1(
	. clk(clk)  ,
	.rst_n(rst) ,
    .second(second),
    .minute(minute)
);
	always #5 clk = ~clk;  // Create clock with period=10 
  initial begin
  rst=0;
 #10 rst=1;
 #36620;
 $finish;
end  
    
endmodule

仿真图如下:

全部评论

相关推荐

2025-12-11 14:24
门头沟学院 Java
牛客35720396...:不要用boss,全是骗
点赞 评论 收藏
分享
01-21 20:09
武汉大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务