📄 traffic.lst
字号:
223 3 delay(5);
224 3 led1=1;
225 3 P1=table[t1/10];
226 3 led2=0;
227 3 delay(5);
228 3 led2=1;
229 3
230 3 }
231 2 if(stateflag ==2)
232 2 {
233 3 if(K4 == 0)
234 3 {
235 4 delay(30);
236 4 if(K4 == 0)
237 4 {
238 5 if(t2<99)
239 5 t2++ ;
240 5 speaker();
241 5 while(K4==0);
C51 COMPILER V7.50 TRAFFIC 05/25/2008 20:12:44 PAGE 5
242 5 }
243 4 }
244 3 if(K3 == 0)
245 3 {
246 4 delay(30);
247 4 if(K3 == 0)
248 4 {
249 5 if(t2>1)
250 5 t2-- ;
251 5 speaker();
252 5 while(K3==0);
253 5 }
254 4
255 4 }
256 3 P1=table[t2%10]; //数码管动态显示
257 3 led1=0;
258 3 delay(5);
259 3 led1=1;
260 3 P1=table[t2/10];
261 3 led2=0;
262 3 delay(5);
263 3 led2=1;
264 3
265 3 }
266 2 if(stateflag ==3)
267 2 {
268 3 if(K4 == 0)
269 3 {
270 4 delay(30);
271 4 if(K4 == 0)
272 4 {
273 5 if(t3<99)
274 5 t3++ ;
275 5 speaker();
276 5 while(K4==0);
277 5 }
278 4 }
279 3 if(K3 == 0)
280 3 {
281 4 delay(30);
282 4 if(K3 == 0)
283 4 {
284 5 if(t3>1)
285 5 t3-- ;
286 5 speaker();
287 5 while(K3==0);
288 5 }
289 4
290 4 }
291 3 P1=table[t3%10]; //数码管动态显示
292 3 led1=0;
293 3 delay(5);
294 3 led1=1;
295 3 P1=table[t3/10];
296 3 led2=0;
297 3 delay(5);
298 3 led2=1;
299 3
300 3 }
301 2 if(stateflag ==4)
302 2 {
303 3 if(K4 == 0)
C51 COMPILER V7.50 TRAFFIC 05/25/2008 20:12:44 PAGE 6
304 3 {
305 4 delay(30);
306 4 if(K4 == 0)
307 4 {
308 5 if(t4<99)
309 5 t4++ ;
310 5 speaker();
311 5 while(K4==0);
312 5 }
313 4 }
314 3 if(K3 == 0)
315 3 {
316 4 delay(30);
317 4 if(K3 == 0)
318 4 {
319 5 if(t4>1)
320 5 t4-- ;
321 5 speaker();
322 5 while(K3==0);
323 5 }
324 4
325 4 }
326 3 P1=table[t4%10]; //数码管动态显示
327 3 led1=0;
328 3 delay(5);
329 3 led1=1;
330 3 P1=table[t4/10];
331 3 led2=0;
332 3 delay(5);
333 3 led2=1;
334 3
335 3 }
336 2 if(K2==0)
337 2 {
338 3 delay(10);
339 3 if(K2==0)
340 3 {
341 4 flag=0;
342 4 EA=1;
343 4 stateflag =0;
344 4 break;
345 4 }
346 3 }
347 2 }
348 1 }
349
350
351
352 /*****************************************************************************
353 ** 函数名称:led()
354 ** 功能描述:数码管倒计时显示程序
355 ** 输 入: n
356 ** 输 出:
357 ** 全局变量:
358 ** 调用模块:
359 **
360 **----------------------------------------------------------------------------
361 ******************************************************************************/
362 void display(char state)
363 {if(state!=6) //首先判断是否紧急状态,整风进行正常的4种状态的自动转变
364 1 {if(state==1) //S1状态的交通指示灯的亮灭情况
365 2 {P0=0x1e;
C51 COMPILER V7.50 TRAFFIC 05/25/2008 20:12:44 PAGE 7
366 3 CO1=0;
367 3 CO2=1;
368 3 CO3=0;
369 3 CO4=1;
370 3 }
371 2 if(state==2) //S2状态的交通指示灯的亮灭情况
372 2 {P0=0x1d;
373 3 CO1=0;
374 3 CO2=1;
375 3 CO3=1;
376 3 CO4=0;
377 3 }
378 2 if(state==3) //S3状态的交通指示灯的亮灭情况
379 2 {P0=0x33;
380 3 CO1=0;
381 3 CO2=1;
382 3 CO3=0;
383 3 CO4=1;
384 3 }
385 2 if(state==4) //S4状态的交通指示灯的亮灭情况
386 2 {P0=0x2b;
387 3 CO1=1;
388 3 CO2=0;
389 3 CO3=0;
390 3 CO4=1;
391 3 }
392 2 P1=table[(standard-second)%10]; //数码管动态显示
393 2 led1=0;
394 2 delay(5);
395 2 led1=1;
396 2 P1=table[(standard-second)/10];
397 2 led2=0;
398 2 delay(5);
399 2 led2=1;
400 2 }
401 1 if(state==6) //紧急状态的交通灯的亮灭情况及数码管显示99
402 1 {P0=0x1b;
403 2 CO1=0;
404 2 CO2=1;
405 2 CO3=0;
406 2 CO4=1;
407 2 P1=table[9];
408 2 led1=0;
409 2 led2=0;
410 2 speaker1();
411 2 }
412 1 }
413
414 /*****************************************************************************
415 ** 函数名称:main()
416 ** 功能描述:主程序
417 ** 输 入:
418 ** 输 出:
419 ** 全局变量:
420 ** 调用模块:
421 **
422 **----------------------------------------------------------------------------
423 ******************************************************************************/
424 void main()
425 {
426 1 standard=t1;
427 1 second=0; //设置初始时间
C51 COMPILER V7.50 TRAFFIC 05/25/2008 20:12:44 PAGE 8
428 1 TH0=(65536-50000)/256; //中断设置初始化
429 1 TL0=(65536-50000)%256;
430 1 EA=1;ET0=1;TMOD=0x21;TR0=1; //开中断总开关,计数器0允许中断,设置中断模式,启动计数器0
431 1 while(1) //死循环,进入显示,主要是动态显示原理
432 1 {
433 2 key();
434 2 display(state); //调用交通状态,状态机原理
435 2 }
436 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 897 ----
CONSTANT SIZE = 10 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 9 1
IDATA SIZE = ---- ----
BIT SIZE = 1 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -