標題: LED模擬交通燈情況實驗 [打印本頁]

作者: zny    時間: 2019-6-5 10:37
標題: LED模擬交通燈情況實驗
在程序運行后十字路口中東西南北方向的紅綠燈循環(huán)點亮,之
間間隔黃燈。其中紅綠燈的顏色變化間隔 2000ms,而黃燈顏色變化 200ms,閃爍 5 次,程
序中為 LED 變化提供了標準延時


#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 t;
                while(x--)
                {
                                for(t=120;t>0;t--);
                }
}

void Traffic_lignt()
{int i=0;
                switch(Operation_Type)
        {
                        case 1:
                                RED_A=1;YELLOW_A=1;GREEN_A=0;
                                RED_B=0;YELLOW_B=1;GREEN_B=1;
                                DelayMS(1000);       
                          GREEN_A=1;
                       
                        case 2:
                                for(i=0;i<5;i++){   
                                        YELLOW_A=0;
                                        DelayMS(200);                          
                                        YELLOW_A=1;
                                        DelayMS(200);       
                        }
                       
                       
                        case 3:
                                RED_A=0;YELLOW_A=1;GREEN_A=1;
                                RED_B=1;YELLOW_B=1;GREEN_B=0;
                                DelayMS(1000);       
                                RED_A=1;

                        case 4:
                                for(i=0;i<5;i++){   
                                        YELLOW_B=0;
                                        DelayMS(200);                          
                                        YELLOW_B=1;
                                        DelayMS(200);
                        }
                }
        }
       
void main()
{
                while(1)
        {
                        Traffic_lignt();
        }
}


仿真原理圖如下




需要的可以下載文件,打開即可使用。
LED 紅綠燈實驗.zip (63.46 KB, 下載次數(shù): 7)







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