题解 | #简易秒表#

简易秒表

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

仿真图如下:

全部评论

相关推荐

宇智波爱学习:我还没收到笔试
投递荣耀等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务