forked from li237340453/VHDL-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.vhd.bak
231 lines (208 loc) · 7.23 KB
/
control.vhd.bak
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity control is
Port (
CLK :in std_logic; --时钟信号
Num :in std_logic_vector(3 downto 0);
anxia :in std_logic;
rData1 :in std_logic_vector(23 downto 0);
dainzhen8x8 :out std_logic_vector(2 downto 0);
guannum :out std_logic_vector(2 downto 0);
Disp1 :out std_logic_vector(23 downto 0);
Disp2 :out std_logic_vector(23 downto 0);
Start :out std_logic;
Start1 :out std_logic
);
end control;
architecture control of control is
signal s_dianzhendata :std_logic_vector(2 downto 0);
signal temporary1 :std_logic_vector(23 downto 0);
signal temporary2 :std_logic_vector(23 downto 0);
signal s_data2 :std_logic_vector(23 downto 0);
signal s_guannum :std_logic_vector(2 downto 0);
signal D6 :std_logic_vector(3 downto 0);
signal D5 :std_logic_vector(3 downto 0);
signal D4 :std_logic_vector(3 downto 0);
signal D3 :std_logic_vector(3 downto 0);
signal D2 :std_logic_vector(3 downto 0);
signal D1 :std_logic_vector(3 downto 0);
signal temp :std_logic_vector(3 downto 0);
signal s_start :std_logic;
signal s_start1 :std_logic;
begin
----------------------------------------------------
process(CLK)
variable Cnt: integer range 0 to 50000000;
variable NumCnt: integer range 0 to 5;
variable i: integer range 0 to 7;
variable k: integer range 0 to 6;
begin
if CLK'event and CLK='1'then
case i is
when 0 => s_dianzhendata <= "110";
s_guannum <= "000";
if anxia='1' then
if Num="1010" then
i := i + 1;
NumCnt := 5;
temporary1(19 downto 0) <= rData1(19 downto 0); --存入随机数字
temporary1(23 downto 20) <= X"F";
end if;
end if;
s_start <= '0';
s_data2 <= X"FFFFFF";
when 1 => s_dianzhendata <= conv_std_logic_vector(NumCnt,3);
s_guannum <= "001";
if NumCnt=0 then
temporary2 <= temporary1;
temporary1 <= X"FFFFFF";
Cnt := 0;
i := i + 1;
end if;
if Cnt<50000000 then
Cnt := Cnt + 1;
else
Cnt := 0;
if NumCnt>0 then
NumCnt := NumCnt - 1; --计算五秒倒计时
end if;
end if;
when 2 => if anxia='1' then
if Num<"1010" then
--存入输入的数字
s_data2(3 downto 0) <= Num;
s_data2(7 downto 4) <= s_data2(3 downto 0) ;
s_data2(11 downto 8) <= s_data2(7 downto 4);
s_data2(15 downto 12) <= s_data2(11 downto 8);
s_data2(19 downto 16) <= s_data2(15 downto 12);
elsif Num="1010" then
if s_data2(19 downto 0)=temporary2(19 downto 0) then
temporary1 <= rData1;
i := i + 1;
s_start1 <= '1';
NumCnt := 5;
s_guannum <= "010";
else
temporary1(19 downto 0) <= rData1(19 downto 0);
temporary1(23 downto 20) <= X"F";
i := 1;
NumCnt := 5;
s_guannum <= "001";
end if;
s_data2 <= X"FFFFFF";
elsif Num="1011" then
i := 0;
end if;
end if;
when 3 => s_dianzhendata <= conv_std_logic_vector(NumCnt,3);
s_start1 <= '0';
s_guannum <= "010";
if NumCnt=0 then
temporary2 <= temporary1;
temporary1 <= X"FFFFFF";
Cnt := 0;
i := i + 1;
end if;
if Cnt<50000000 then --计算一秒的时间
Cnt := Cnt + 1;
else
Cnt := 0;
if NumCnt>0 then
NumCnt := NumCnt - 1;
end if;
end if;
when 4 => if anxia='1' then
if Num<"1010" then
s_data2(3 downto 0) <= Num;
s_data2(7 downto 4) <= s_data2(3 downto 0) ;
s_data2(11 downto 8) <= s_data2(7 downto 4);
s_data2(15 downto 12) <= s_data2(11 downto 8);
s_data2(19 downto 16) <= s_data2(15 downto 12);
s_data2(23 downto 20) <= s_data2(19 downto 16);
elsif Num="1010" then
temporary1 <= rData1;
if s_data2=temporary2 then --如果数字输入正确
i := i + 1;
s_start1 <= '1';
NumCnt := 3;
s_guannum <= "011";
else
temporary1(19 downto 0) <= rData1(19 downto 0);
temporary1(23 downto 20) <= X"F";
i := 1;
NumCnt := 5;
s_guannum <= "010";
end if;
s_data2 <= X"FFFFFF";
elsif Num="1011" then
i := 0;
end if;
end if;
when 5 => s_dianzhendata <= conv_std_logic_vector(NumCnt,3);
s_start1 <= '0';
s_guannum <= "011";
if NumCnt=0 then
temporary2 <= temporary1;
temporary1 <= X"FFFFFF";
Cnt := 0;
i := i + 1;
end if;
if Cnt<50000000 then
Cnt := Cnt + 1;
else
Cnt := 0;
if NumCnt>0 then
NumCnt := NumCnt - 1;
end if;
end if;
when 6 => if anxia='1' then
if Num<"1010" then
s_data2(3 downto 0) <= Num;
s_data2(7 downto 4) <= s_data2(3 downto 0) ;
s_data2(11 downto 8) <= s_data2(7 downto 4);
s_data2(15 downto 12) <= s_data2(11 downto 8);
s_data2(19 downto 16) <= s_data2(15 downto 12);
s_data2(23 downto 20) <= s_data2(19 downto 16);
elsif Num="1010" then
temporary1 <= rData1;
if s_data2=temporary2 then
i := i + 1;
k := 0;
NumCnt := 3;
s_guannum <= "000";
else
temporary1(19 downto 0) <= rData1(19 downto 0);
temporary1(23 downto 20) <= X"F";
i := 1;
NumCnt := 3;
s_guannum <= "011";
end if;
s_data2 <= X"FFFFFF";
elsif Num="1011" then
i := 0;
end if;
end if;
when 7 => s_dianzhendata <= "111";
s_start <= '1';
s_start1 <= '0';
s_data2 <= X"FFFFFF";
temporary1 <= X"FFFFFF";
if anxia='1' then
if Num="1011" then
i := 0;
end if;
end if;
end case;
end if;
end process;
------------------------------------------------
dainzhen8x8 <= s_dianzhendata;
guannum <= s_guannum;
Disp1 <= temporary1;
Disp2 <= s_data2;
Start <= s_start;
Start1 <= s_start1;
-------------------------------------------------
end control;