|
51单片机随意做的简单信号灯
代码如下:
#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
113.89 KB, 下载次数: 4, 下载积分: 黑币 -5
评分
-
查看全部评分
|