📄 traffic.lst
字号:
157 3 break;
158 3
159 3 case 'T': //设置时间命令
160 3 if (readtime (&inline[i+1])) //获取输入时间
161 3 {
162 4 clk_time.hour = ztime.hour;
163 4 clk_time.min = ztime.min;
164 4 clk_time.sec = ztime.sec;
165 4 }
166 3 break;
167 3
168 3 case 'S': //设置开始时间命令
169 3 if (readtime (&inline[i+1])) //获取输入时间
170 3 {
171 4 start_time.hour = ztime.hour;
172 4 start_time.min = ztime.min;
173 4 start_time.sec = ztime.sec;
174 4 }
175 3 break;
176 3
177 3 case 'E': //设置结束时间命令
178 3 if (readtime (&inline[i+1])) //获取输入时间
179 3 {
C51 COMPILER V8.08 TRAFFIC 04/25/2008 15:44:36 PAGE 4
180 4 end_time.hour = ztime.hour;
181 4 end_time.min = ztime.min;
182 4 end_time.sec = ztime.sec;
183 4 }
184 3 break;
185 3
186 3 default: //无效指令
187 3 printf("Error!");
188 3 printf (sysmenu); //显示系统命令菜单
189 3 break;
190 3 }
191 2 }
192 1 }
193
194
195 bit signalon () //检查系统时钟是否处在开始时间和结束时间之间
196 {
197 1 if (memcmp (&start_time, &end_time, sizeof (struct time)) < 0)
198 1 {
199 2 if (memcmp (&start_time, &clk_time, sizeof (struct time)) < 0 &&
200 2 memcmp (&clk_time, &end_time, sizeof (struct time)) < 0)
201 2 return (1); //红绿灯处于活跃状态
202 2 }
203 1 else
204 1 {
205 2 if (memcmp (&end_time, &clk_time, sizeof (start_time)) > 0 &&
206 2 memcmp (&clk_time, &start_time, sizeof (start_time)) > 0)
207 2 return (1);
208 2 }
209 1 return (0); //信号结束,开始闪烁黄灯
210 1 }
211
212
213 void blinking () _task_ BLINKING //任务3
214 {
215 1 red = 0; //熄灭红灯
216 1 yellow = 0; //熄灭黄灯
217 1 green = 0; //熄灭绿灯
218 1 stop = 0; //熄灭行人红灯
219 1 walk = 0; //熄灭行人绿灯
220 1
221 1 while (1) //闪烁循环
222 1 {
223 2 yellow = 1; //点亮黄灯
224 2 os_wait (K_TMO, 30, 0); //等待超时
225 2 yellow = 0; //熄灭黄灯
226 2 os_wait (K_TMO, 30, 0); //等待超时
227 2 if (signalon ()) //如果闪烁时间段结束
228 2 {
229 3 os_create_task (LIGHTS); //启动任务4
230 3 os_delete_task (BLINKING); //停止任务3
231 3 }
232 2 }
233 1 }
234
235
236 void lights () _task_ LIGHTS //任务4
237 {
238 1 red = 1; //点亮红灯
239 1 yellow = 0; //熄灭黄灯
240 1 green = 0; //熄灭绿灯
241 1 stop = 1; //点亮行人红灯
C51 COMPILER V8.08 TRAFFIC 04/25/2008 15:44:36 PAGE 5
242 1 walk = 0; //熄灭行人绿灯
243 1
244 1 while (1) //主循环
245 1 {
246 2 os_wait (K_TMO, 30, 0); //等待超时
247 2 if (!signalon ()) //如果系统时间处在活跃时间之外
248 2 {
249 3 os_create_task (BLINKING); //启动任务3
250 3 os_delete_task (LIGHTS); //停止任务4
251 3 }
252 2 yellow = 1;
253 2 os_wait (K_TMO, 30, 0); //等待超时
254 2
255 2 red = 0;
256 2 yellow = 0; //为主干道点亮绿灯
257 2 green = 1;
258 2
259 2 os_clear_signal (LIGHTS);
260 2 os_wait (K_TMO, 30, 0); //等待超时
261 2 os_wait (K_TMO + K_SIG, 300, 0); //等待超时和信号
262 2
263 2 yellow = 1;
264 2 green = 0;
265 2 os_wait (K_TMO, 30, 0); //等待超时
266 2 red = 1; //为主干道点亮红灯
267 2 yellow = 0;
268 2
269 2 os_wait (K_TMO, 30, 0); //等待超时
270 2 stop = 0; //为行人点亮绿灯,放行
271 2 walk = 1;
272 2
273 2 os_wait (K_TMO, 100, 0); //等待超时
274 2 stop = 1; //为行人点亮红灯
275 2 walk = 0;
276 2 }
277 1 }
278
279
280 void buttonread () _task_ buttonREAD //任务5
281 {
282 1 while (1)
283 1 {
284 2 if (button) //若行人按钮按下
285 2 {
286 3 os_send_signal (LIGHTS); //向任务4发送信号
287 3 }
288 2 os_wait (K_TMO, 3, 0); //等待超时
289 2 }
290 1 }
291
292 void get_escape () _task_ GET_ESC //任务6
293 {
294 1 while (1)
295 1 {
296 2 if (_getkey () == ESC) //如果ESC 键输入,置escape标志
297 2 escape = 1;
298 2 if (escape) //如果有escape标志,向任务1发送信号
299 2 {
300 3 os_send_signal (COMMAND);
301 3 }
302 2 }
303 1 }
C51 COMPILER V8.08 TRAFFIC 04/25/2008 15:44:36 PAGE 6
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 797 ----
CONSTANT SIZE = 633 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 12 1
IDATA SIZE = 16 ----
BIT SIZE = 2 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -