题解 | #简易秒表#

简易秒表

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

仿真图如下:

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 12:02
ssob上原来真有BOSS啊
硫蛋蛋:这种也是打工的,只不是是给写字楼房东打工
点赞 评论 收藏
分享
06-01 21:50
已编辑
天津理工大学 Java
点赞 评论 收藏
分享
05-26 10:24
门头沟学院 Java
qq乃乃好喝到咩噗茶:其实是对的,线上面试容易被人当野怪刷了
找工作时遇到的神仙HR
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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