一个程序
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit checkport=P3^2;
sbit RED_A=P1^2; //东西向灯
sbit YELLOW_A=P1^1;
sbit GREEN_A=P1^0;
sbit RED_B=P1^5; //南北向灯
sbit YELLOW_B=P1^4;
sbit GREEN_B=P1^3;
uchar Operation_Type=1; //闪烁次数,操作类型变量
uint Flash_Count=0,n;
void DelayMS(int x)
{
uchar i;
while(x--)for(i=0;i<120;i++);
}
void Traffic_Light()
{
checkport=1;
n=10;
switch(Operation_Type)
{
case 1: //东西向绿灯与南北向红灯亮
RED_A=1;YELLOW_A=1;GREEN_A=0;
RED_B=0;YELLOW_B=1;GREEN_B=1;
DelayMS(2000);
Operation_Type=2;
break;
case 2: //东西向黄灯闪烁,绿灯关闭
DelayMS(300);
if(checkport==0){DelayMS(5000);}
YELLOW_A=~YELLOW_A;GREEN_A=1;
if(++Flash_Count!=10) return;
Flash_Count=0;
Operation_Type=3;
break;
case 3: //东西向红灯,南北向绿灯亮
RED_A=0;YELLOW_A=1;GREEN_A=1;
RED_B=1;YELLOW_B=1;GREEN_B=0;
DelayMS(2000);
Operation_Type=4;
break;
case 4: //南北向黄灯闪烁 5 次
DelayMS(300);
YELLOW_B=~YELLOW_B;GREEN_B=1;
if(++Flash_Count!=10) return;
Flash_Count=0;
Operation_Type=1;
};
}
void main()
{
while(1) Traffic_Light();
}
if(checkport==0){DelayMS(5000);}帮帮忙,详细解释一下这句,是不是传感器延时?
[解决办法]
delay:是延时的意思,ms:毫秒。
delayms:就是指毫秒级的延时程序