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
|
// `define ASYNC_RESET
module fsm_test(clk, reset, button_a, button_b, red_a, green_a, red_b, green_b);
input clk, reset, button_a, button_b;
output reg red_a, green_a, red_b, green_b;
(* gentb_constant = 0 *)
wire reset;
integer state;
reg [3:0] cnt;
`ifdef ASYNC_RESET
always @(posedge clk, posedge reset)
`else
always @(posedge clk)
`endif
begin
cnt <= 0;
red_a <= 1;
red_b <= 1;
green_a <= 0;
green_b <= 0;
if (reset)
state <= 100;
else
case (state)
100: begin
if (button_a && !button_b)
state <= 200;
if (!button_a && button_b)
state <= 300;
end
200: begin
red_a <= 0;
green_a <= 1;
cnt <= cnt + 1;
if (cnt == 5)
state <= 210;
end
210: begin
red_a <= 0;
green_a <= cnt[0];
cnt <= cnt + 1;
if (cnt == 10)
state <= 100;
end
300: begin
red_b <= 0;
green_b <= 1;
cnt <= cnt + 1;
if (cnt == 5)
state <= 310;
end
310: begin
red_b <= 0;
green_b <= cnt[0];
cnt <= cnt + 1;
if (cnt == 10)
state <= 100;
end
endcase
end
endmodule
|