题解 | 简易秒表

简易秒表

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

`timescale 1ns/1ns

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)
if(!rst_n)
  second <= 0;
else if(second==6'd60)
  second <= 6'd1;
else if(minute==6'd60)
  second <= 0;
else
  second <= second + 1;

always@(posedge clk or negedge rst_n)
if(!rst_n)
  minute <= 0;
else if(second==6'd60)
  minute <= minute + 1;
else if(minute==6'd60)
  minute <= 0;
	
	
endmodule
`timescale 1ns/1ns

module testbench();

	reg clk,rst_n;

	wire [5:0]second;
	wire [5:0]minute;
always #1 clk = ~clk;	
initial begin
	$dumpfile("out.vcd");
	$dumpvars(0,testbench);
	clk = 0;
	rst_n = 0;
    #3 rst_n=1;
	#180;
	$finish;
end


count_module dut(
	.clk(clk),
	.rst_n(rst_n),
	.second(second),
	.minute(minute)
);
endmodule

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-10 12:05
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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