交通燈運行一周耗時40秒,運行情況是東西方向綠燈亮10秒后滅,黃燈閃爍3秒后滅,左轉向燈亮4秒后滅,黃燈閃爍3秒后滅,紅燈亮20秒
南北方向交通燈運行情況是紅燈亮20秒后滅,綠燈亮10秒后滅,黃燈閃爍3秒后滅
左轉向燈亮4秒后滅,黃燈閃爍3秒
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
0.png (21.18 KB, 下載次數: 44)
下載附件
2018-5-3 02:14 上傳
0.jpg (37.75 KB, 下載次數: 52)
下載附件
2018-5-3 02:13 上傳
單片機源程序如下:
- #include <reg52.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 LEFT_A=P2^0;
- sbit RED_B=P0^3;
- sbit YELLOW_B=P0^4;
- sbit GREEN_B=P0^5;
- sbit LEFT_B=P2^1;
- uchar Flash_Count = 0;
- Operation_Type = 1;
- void DelayMS(uint x)
- {
- uchar t;
- while(x--)
- {
- for(t=120;t>0;t--);
- }
- }
- void Traffic_lignt()
- {
- switch(Operation_Type)
- {
- case 1:
- RED_A=1;YELLOW_A=1;GREEN_A=0;LEFT_A=1;
- RED_B=0;YELLOW_B=1;GREEN_B=1;LEFT_B=1;
- DelayMS(10000);
- Operation_Type = 2;
- break;
- case 2:
- GREEN_A=1;
- DelayMS(300);
- YELLOW_A=~YELLOW_A;
- if(++Flash_Count !=10)
- return;
- Flash_Count=0;
- Operation_Type = 3;
- break;
- case 3:
- RED_A=1;YELLOW_A=1;GREEN_A=1;LEFT_A=0;
- // RED_B=0;YELLOW_B=1;GREEN_B=1;LEFT_B=1;
- DelayMS(4000);
- Operation_Type = 4;
- break;
- case 4:
- LEFT_A=1;
- DelayMS(300);
- YELLOW_A=~YELLOW_A;
- if(++Flash_Count !=10)
- return;
- Flash_Count=0;
- Operation_Type = 5;
- break;
- case 5:
- RED_A=0;YELLOW_A=1;GREEN_A=1;LEFT_A=1;
- RED_B=1;YELLOW_B=1;GREEN_B=0;LEFT_B=1;
- DelayMS(10000);
- Operation_Type = 6;
- break;
- case 6:
- GREEN_B=1;
- DelayMS(300);
- YELLOW_B=~YELLOW_B;
- if(++Flash_Count !=10)
- return;
- Flash_Count=0;
- Operation_Type = 7;
- break;
- case 7:
- // RED_A=0;YELLOW_A=1;GREEN_A=1;LEFT_A=1;
- RED_B=1;YELLOW_B=1;GREEN_B=1;LEFT_B=0;
- DelayMS(4000);
- Operation_Type = 8;
- break;
- case 8:
- LEFT_B=1;
- // RED_A=0;YELLOW_A=1;GREEN_A=1;LEFT_A=1;
- DelayMS(300);
- YELLOW_B=~YELLOW_B;
- if(++Flash_Count !=10)
- return;
- Flash_Count=0;
- Operation_Type = 1;
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
LED模擬交通燈(帶左轉向).zip
(70.12 KB, 下載次數: 46)
2018-5-2 21:43 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|