-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount_1s.v
More file actions
93 lines (87 loc) · 1.44 KB
/
Copy pathcount_1s.v
File metadata and controls
93 lines (87 loc) · 1.44 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
//计时模块
module count_1s
(
input clk, //系统时钟
input sys_reset_n, //复位信号
input EN, //使能 保持
output reg [7:0] data_s, //秒计时器
output reg [7:0] data_m, //分钟计时器
output [3:0] point //点
);
parameter time_60=8'd60;
parameter MAX_NUM=28'd24_999_999;
reg [27:0] cnt; //1s计数器
reg clk_1s; //1s脉冲
reg flag_1m; //1m计时
assign point=4'b0100;
//1s计时
always @(posedge clk or negedge sys_reset_n)
begin
if(!sys_reset_n)
begin
cnt<=1'b0;
clk_1s<=1'b0;
end
else if(!EN)
begin
cnt<=cnt; //保持
clk_1s<=clk_1s;
end
else if(cnt<MAX_NUM)
begin
cnt<=cnt+1'b1;
end
else
begin
cnt<=0;
clk_1s<=~clk_1s; //翻转
end
end
// 秒加1
always @(negedge clk_1s or negedge sys_reset_n)
begin
if(!sys_reset_n)
begin
data_s<=0;
flag_1m<=0;
end
else if(!EN)
begin
data_s<=data_s; //保持
flag_1m<=flag_1m;
end
else if(data_s < time_60-1)
begin
data_s<=data_s+1'b1;
flag_1m<=0;
end
else
begin
data_s<=0;
flag_1m<=1;
end
end
//分钟加一
always @(posedge flag_1m or negedge sys_reset_n)
begin
if(!sys_reset_n)
begin
data_m<=0;
end
else if(!EN)
begin
data_m<=data_m; //保持
end
else
begin
if(data_m<time_60-1)
begin
data_m<=data_m+1'b1;
end
else
begin
data_m<=0;
end
end
end
endmodule