This repository has been archived by the owner on Jun 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eclock.v
148 lines (141 loc) · 2.77 KB
/
eclock.v
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
module eclock(
clk,
rst,
shot,
shotClk,
shotRst,
hour_add,
hour_sub,
hour_tens,
hour_digits,
min_add,
min_sub,
min_tens,
min_digits,
sec_add,
sec_sub,
sec_tens,
sec_digits
);
input clk, rst, shot, shotClk, shotRst;
input hour_add, hour_sub, min_add, min_sub, sec_add, sec_sub;
output [3:0] hour_tens, hour_digits;
output [3:0] min_tens, min_digits;
output [3:0] sec_tens, sec_digits;
reg [5:0] count_min, count_hour, count_sec;
reg [2:0] count_shot;
reg count_shotLED1, count_shotLED2, count_shotLED3, count_shotLED4, count_shotLED5, count_shotLED6;
// binary to decimal
assign hour_tens = (count_shotLED6) ? 4'he : count_hour / 10;
assign hour_digits = (count_shotLED5) ? 4'he : count_hour % 10;
assign min_tens = (count_shotLED4) ? 4'he : count_min / 10;
assign min_digits = (count_shotLED3) ? 4'he : count_min % 10;
assign sec_tens = (count_shotLED2) ? 4'he : count_sec / 10;
assign sec_digits = (count_shotLED1) ? 4'he : count_sec % 10;
always @ (posedge shot or negedge shotRst)
begin
if (!shotRst)
begin
count_shot <= 0;
end
else
begin
count_shot <= count_shot + 1;
end
end
always @ (posedge shotClk or negedge shotRst)
begin
if (!shotRst)
begin
count_shotLED1 <= 0;
count_shotLED2 <= 0;
count_shotLED3 <= 0;
count_shotLED4 <= 0;
count_shotLED5 <= 0;
count_shotLED6 <= 0;
end
else if (count_shot == 1)
begin
count_shotLED1 <= 1;
end
else if (count_shot == 2)
begin
count_shotLED2 <= 1;
end
else if (count_shot == 3)
begin
count_shotLED3 <= 1;
end
else if (count_shot == 4)
begin
count_shotLED4 <= 1;
end
else if (count_shot == 5)
begin
count_shotLED5 <= 1;
end
else if (count_shot == 6)
begin
count_shotLED6 <= 1;
end
end
always @ (posedge clk or negedge rst)
begin
// reset
if (!rst)
begin
count_hour <= 0;
count_min <= 0;
count_sec <= 0;
end
// hour operation
else if (hour_add)
begin
count_hour <= count_hour + 1;
end
else if (hour_sub)
begin
count_hour <= count_hour - 1;
end
// hour maximum
else if (count_hour >= 23 && count_min >= 59 && count_sec >= 59)
begin
count_min <= 0;
count_hour <= 0;
count_sec <= 0;
end
// minute operation
else if (min_add)
begin
count_min <= count_min + 1;
end
else if (min_sub)
begin
count_min <= count_min - 1;
end
// minute maximum
else if (count_min >= 59)
begin
count_min <= 0;
count_hour <= count_hour + 1;
end
// second operation
else if (sec_add)
begin
count_sec <= count_sec + 2;
end
else if (sec_sub)
begin
count_sec <= count_sec - 2;
end
// second maximum
else if (count_sec >= 59)
begin
count_sec <= 0;
count_min <= count_min + 1;
end
// normal operation
else
count_sec <= count_sec + 1;
end
endmodule