|
51單片機隨意做的簡單信號燈
QQ瀏覽器截圖20190517104500.png (54.35 KB, 下載次數: 26)
下載附件
2019-5-17 10:45 上傳
代碼如下:
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit RED_A=P1^0;
sbit YELLOW_A=P1^1;
sbit GREEN_A=P1^2;
sbit RED_B=P1^3;
sbit YELLOW_B=P1^4;
sbit GREEN_B=P1^5;
uchar Flash_Count = 0;
Operation_Type = 1;
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--) //i=xms即延時約xms毫秒
for(j=110;j>0;j--);
}
void Traffic_lignt()
{
switch(Operation_Type)
{
case 1:
RED_A=0;YELLOW_A=0;GREEN_A=1;
RED_B=1;YELLOW_B=0;GREEN_B=0;
delayms(2000);
Operation_Type = 2;
break;
case 2:
delayms(200);
GREEN_A=0;
YELLOW_A=~YELLOW_A;
if(++Flash_Count !=10)
return;
Flash_Count=0;
Operation_Type = 3;
break;
case 3:
RED_A=1;YELLOW_A=0;GREEN_A=0;
RED_B=0;YELLOW_B=0;GREEN_B=1;
delayms(2000);
Operation_Type = 4;
break;
case 4:
delayms(200);
GREEN_B=0;
YELLOW_B=~YELLOW_B;
if(++Flash_Count !=10)
return;
Flash_Count=0;
Operation_Type = 1;
break;
}
}
void main(void)
{
while(1)
{
Traffic_lignt();
}
}
|
-
-
led.rar
2019-5-14 10:52 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
113.89 KB, 下載次數: 4, 下載積分: 黑幣 -5
評分
-
查看全部評分
|