|
在程序運(yùn)行后十字路口中東西南北方向的紅綠燈循環(huán)點(diǎn)亮,之
間間隔黃燈。其中紅綠燈的顏色變化間隔 2000ms,而黃燈顏色變化 200ms,閃爍 5 次,程
序中為 LED 變化提供了標(biāo)準(zhǔn)延時(shí)
#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();
}
}
仿真原理圖如下
截圖.png (31.97 KB, 下載次數(shù): 32)
下載附件
實(shí)驗(yàn)連接顯示圖
2019-6-5 10:31 上傳
需要的可以下載文件,打開即可使用。
LED 紅綠燈實(shí)驗(yàn).zip
(63.46 KB, 下載次數(shù): 7)
2019-6-5 10:34 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|