標(biāo)題: 求基于單片機(jī)的交通燈信號燈系統(tǒng) [打印本頁]

作者: 人民子弟兵    時間: 2016-12-29 22:07
標(biāo)題: 求基于單片機(jī)的交通燈信號燈系統(tǒng)
求基于單片機(jī)的交通燈信號燈系統(tǒng)

作者: 向前看zk    時間: 2016-12-30 09:25
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit RED_A=P0^0;
sbit YELLOW_A=P0^1;
sbit GREEN_A=P0^2;
sbit RED_B=P0^3;
sbit YELLOW_B=P0^4;
sbit GREEN_B=P0^5;
uchar Flash_Count=0,Operation_Type=1;
void DelayMs(uint x)
{
uchar i;
while(x--)for(i=0;i<120;i++);
}
void Traffic_Light()
{
        switch(Operation_Type)
     {
                case 1:RED_A=1;YELLOW_A=1;GREEN_A=0;
                       RED_B=0;YELLOW_B=1;GREEN_B=1;
                       DelayMs(2000);
                       Operation_Type=2;
                       break;
                case 2:DelayMs(300);
                       YELLOW_A=~YELLOW_A;GREEN_A=1;
                       if(++Flash_Count!=10)return;
                       Flash_Count=0;
                       Operation_Type=3;
                       break;
                case 3:RED_A=0;YELLOW_A=1;GREEN_A=1;
                       RED_B=1;YELLOW_B=1;GREEN_B=0;
                        DelayMs(2000);
             Operation_Type=4;
                       break;
                case 4:DelayMs(300);
                       YELLOW_B=~YELLOW_B;GREEN_B=1;
                       if(++Flash_Count!=10)return;
                       Flash_Count=0;
                         Operation_Type=1;
           }
}
void main()
{
   while(1)Traffic_Light();
}




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1