-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssegment.v
54 lines (45 loc) · 1019 Bytes
/
ssegment.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
module ssegment(
input clk, rst,
input [3:0] hited,
input [3:0] hit,
output reg [7:0] SSEG_AN, SSEG_CA);
parameter FIRST = 8'b1111_1110, THIRD = 8'b1111_1011;
parameter LIFE = 4'd3;
reg [31:0] count2;
reg a;
reg [3:0] score, life;
wire [7:0] w1, w3;
initial begin
score = 4'b0;
life = LIFE;
count2 = 4'b0;
a = 1'b0;
end
always @(posedge clk)//·ÖƵ
begin
count2 = count2 + 1;
if(count2 == 1) a = ~ a;
else if(count2 == 32'h0001ffff) count2 = 0;
end
always @(posedge clk or posedge rst) begin
if(rst) begin
score <= 4'b0;
life <= LIFE;
end
else begin
score <= hit;
life <= LIFE - hited;
end
end
always @(posedge clk) begin
if(a) begin
SSEG_AN <= FIRST;
SSEG_CA <= w1;
end else begin
SSEG_AN <= THIRD;
SSEG_CA <= w3;
end
end
ROM_ssegment R0(score, w1);
ROM_ssegment R1(life, w3);
endmodule