标题: LED模拟交通灯(带左转向)资料分享!(含仿真和程序) [打印本页]

作者: king@    时间: 2016-12-9 22:32
标题: LED模拟交通灯(带左转向)资料分享!(含仿真和程序)


源程序:
  1. #include <reg52.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int

  4. sbit RED_A=P0^0;
  5. sbit YELLOW_A=P0^1;
  6. sbit GREEN_A=P0^2;
  7. sbit LEFT_A=P2^0;
  8. sbit RED_B=P0^3;
  9. sbit YELLOW_B=P0^4;
  10. sbit GREEN_B=P0^5;
  11. sbit LEFT_B=P2^1;

  12. uchar Flash_Count = 0;
  13. Operation_Type = 1;

  14. void DelayMS(uint x)
  15. {
  16.          uchar t;
  17.         while(x--)
  18.         {
  19.                  for(t=120;t>0;t--);
  20.         }
  21. }

  22. void Traffic_lignt()
  23. {
  24.          switch(Operation_Type)
  25.         {
  26.                  case 1:
  27.                         RED_A=1;YELLOW_A=1;GREEN_A=0;LEFT_A=1;
  28.                         RED_B=0;YELLOW_B=1;GREEN_B=1;LEFT_B=1;
  29.                         DelayMS(10000);
  30.                         Operation_Type = 2;
  31.                         break;
  32.                 case 2:
  33.             GREEN_A=1;
  34.                         DelayMS(300);
  35.                         YELLOW_A=~YELLOW_A;
  36.                         if(++Flash_Count !=10)
  37.                                 return;
  38.                         Flash_Count=0;
  39.                         Operation_Type = 3;
  40.                         break;
  41.                 case 3:
  42.                         RED_A=1;YELLOW_A=1;GREEN_A=1;LEFT_A=0;
  43.                 //        RED_B=0;YELLOW_B=1;GREEN_B=1;LEFT_B=1;
  44.                         DelayMS(4000);
  45.                         Operation_Type = 4;
  46.                         break;        
  47.         case 4:
  48.                         LEFT_A=1;
  49.             DelayMS(300);
  50.                         YELLOW_A=~YELLOW_A;
  51.                         if(++Flash_Count !=10)
  52.                                 return;
  53.                         Flash_Count=0;
  54.                         Operation_Type = 5;
  55.                         break;        

  56.         case 5:
  57.             RED_A=0;YELLOW_A=1;GREEN_A=1;LEFT_A=1;
  58.             RED_B=1;YELLOW_B=1;GREEN_B=0;LEFT_B=1;
  59.             DelayMS(10000);
  60.                         Operation_Type = 6;
  61.                         break;
  62.         case 6:
  63.                    GREEN_B=1;  
  64.             DelayMS(300);
  65.                         YELLOW_B=~YELLOW_B;
  66.                         if(++Flash_Count !=10)
  67.                                 return;
  68.                         Flash_Count=0;
  69.             Operation_Type = 7;
  70.                         break;
  71.          case 7:
  72.          //  RED_A=0;YELLOW_A=1;GREEN_A=1;LEFT_A=1;
  73.            RED_B=1;YELLOW_B=1;GREEN_B=1;LEFT_B=0;
  74.            DelayMS(4000);
  75.            Operation_Type = 8;
  76.                    break;
  77.         case 8:
  78.             LEFT_B=1;
  79.            // RED_A=0;YELLOW_A=1;GREEN_A=1;LEFT_A=1;        
  80.             DelayMS(300);
  81.                         YELLOW_B=~YELLOW_B;
  82.                         if(++Flash_Count !=10)
  83.                                 return;
  84.                         Flash_Count=0;
  85.             Operation_Type = 1;
  86.                         break;
  87.         
  88.         }
  89. }

  90. void main()
  91. {
  92.          while(1)
  93.         {
  94.                  Traffic_lignt();        
  95.         }
  96. }
复制代码

资料下载:
LED模拟交通灯(带左转向).zip (70.12 KB, 下载次数: 41)

作者: pexssa    时间: 2017-9-21 11:32
感谢分享
作者: 957    时间: 2017-10-23 23:49
可以私发一份给我吗?没有黑币了,跪求




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1