-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple_machine_2.v
163 lines (138 loc) · 2.12 KB
/
simple_machine_2.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
module simple_machine_2(
input clk,
input reset,
input [1:0] KEY,
output reg [9:0] LEDR,
output wire [7:0] HEX0,
output wire [7:0] HEX1
);
reg [3:0] state;
wire [9:0] a_ledr;
wire [3:0] a_new_state;
sm2_a a(state, KEY, a_new_state, a_ledr);
wire [9:0] b_ledr;
wire [3:0] b_new_state;
sm2_b b(state, KEY, b_new_state, b_ledr);
bcd_decoder bcd_a(a_new_state, 0, HEX0);
bcd_decoder bcd_b(b_new_state, 0, HEX1);
always @(posedge clk)
begin
if (reset)
begin
state <= 0;
end // if
else
begin
case (state)
0: begin
state <= a_new_state;
end
1: begin
state <= b_new_state;
end
default: begin
state <= 0;
end
endcase
end // else
end // always new_state
always @(state)
begin
if (reset)
begin
LEDR <= 10'h3FF;
end
else
begin
case (state)
0: begin
LEDR <= a_ledr;
end
1: begin
LEDR <= b_ledr;
end
default: begin
LEDR <= 0;
end
endcase
end
end // always state
endmodule
module sm2_a(
input [3:0] state,
input [1:0] KEY,
output reg [3:0] out_state,
output reg [9:0] LEDR
);
always @(state)
begin
// if (state != 0)
// begin
// out_state <= 0;
// end
// else
// begin
LEDR <= 10'h2AA;
// if (!KEY[0])
// begin
// out_state <= 1;
// end
//
// else
// begin
// out_state <= 0;
// end
// end
end //always
always @(posedge KEY[0])
begin
if (state == 0)
begin
out_state <= 1;
end
else
begin
out_state <= 0;
end
end
endmodule
module sm2_b(
input [3:0] state,
input [1:0] KEY,
output reg [3:0] out_state,
output reg [9:0] LEDR
);
always @(state)
begin
// if (state != 1)
// begin
// out_state <= 1;
// end
// else
// begin
LEDR <= 10'h155;
// if (!KEY[0])
// begin
// out_state <= 0;
// end
//
// else
// begin
// out_state <= 1;
// end
// end
end //always
always @(posedge KEY[0])
begin
// if (state == 1)
// begin
// out_state <= 0;
// end
//
// else
// begin
// out_state <= 1;
// end
out_state <= !out_state;
end
endmodule