我是靠谱客的博主 可靠大叔,这篇文章主要介绍Verilog实现数字时钟,现在分享给大家,希望可以做个参考。

基于f = 100Hz的Clock设计一个数字时钟,用Verilog实现以下功能
1、产生时、分、秒的计时
2、可通过3个按键来设置时、分、秒值

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
module clock( input clk, input rst_n, input hour_set, input [4:0] hour_set_value, input minute_set, input [5:0] minute_set_value, input second_set, input [5:0] second_set_value, output reg [4:0] hour, output reg [5:0] minute, output reg [5:0] second ) reg clk_1; reg [6:0] cnt; // get 1HZ clk always@(posedge clk or negedge rst_n) begin if(!rst_n) cnt <= 0; else if(cnt == 99) cnt <= 0; else cnt <= cnt + 1; end always@(posedge clk or negedge rst_n) begin if(!rst_n) clk_1 <= 0; else if(cnt < 50) clk_1 <= 0; else clk_1 <= 1; end always@(posedge clk_1 or negedge rst_n) begin if(!rst_n) second <= 0; else begin if(second_set) second <= second_set_value; else if(second == 59) second <= 0; else second <= second + 1; end end always@(posedge clk_1 or negedge rst_n) begin if(!rst_n) minute <= 0; else begin if(minute_set) minute <= minute_set_value; else if( (minute==59) && (second==59) ) minute <= 0; else if(second==59) minute <= minute + 1; end end always@(posedge clk_1 or negedge rst_n) begin if(!rst_n) hour <= 0; else begin if(hour_set) hour <= hour_set_value; else if( (hour==23) && (minute==59) && (second==59) ) hour <= 0; else if((minute==59) && (second==59)) hour <= hour + 1; end end endmodule

最后

以上就是可靠大叔最近收集整理的关于Verilog实现数字时钟的全部内容,更多相关Verilog实现数字时钟内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部