-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.v
58 lines (53 loc) · 1.31 KB
/
check.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
module check(div_clk, rst, btn1, btn2, btn3, data, score);
input div_clk, rst, btn1, btn2, btn3;
input [2:0] data;
reg [2:0] tmp_data;
reg [2:0] tmp_score;
output reg [1:0] score = 2'd0;
reg [31:0] cnt;
always@(posedge div_clk or negedge rst)
begin
if (~rst) begin
score = 2'd0;
cnt <= 32'd0;
tmp_score[2] <= 1'b0;
tmp_score[1] <= 1'b0;
tmp_score[0] <= 1'b0;
tmp_data = data;
end
else begin
if (cnt == 32'd1000) begin
score <= tmp_score[2] + tmp_score[1] + tmp_score[0];
tmp_score[2] <= 1'b0;
tmp_score[1] <= 1'b0;
tmp_score[0] <= 1'b0;
cnt <= 32'd0;
tmp_data = data;
end
else begin
//tmp_score[2] = (!btn1 && tmp_data[2])? 1'b1 :tmp_score[2];
tmp_score[1] = (!btn1 && tmp_data[1])? 1'b1 :tmp_score[1];
tmp_score[0] = (!btn1 && tmp_data[0])? 1'b1 :tmp_score[0];
if (!btn1 && tmp_data[2]) begin
tmp_score[2] = 1'b1;
tmp_data[2] = ~tmp_data[2];
end
else
tmp_score[2] = tmp_score[2];
if (!btn2 && tmp_data[1]) begin
tmp_score[1] = 1'b1;
tmp_data[1] = ~tmp_data[1];
end
else
tmp_score[1] = tmp_score[1];
if (!btn3 && tmp_data[0]) begin
tmp_score[0] = 1'b1;
tmp_data[0] = ~tmp_data[0];
end
else
tmp_score[0] = tmp_score[0];
cnt <= cnt + 32'b1;
end
end
end
endmodule