怎么用delay实现 窗帘开启1/2 且让电机随时停止
#include<reg52.h>
#define uchar unsigned char
sbit D0 = P2^0;
sbit D1 = P2^1;
sbit D2 = P2^2;
sbit K1=P3^0;
sbit K2=P3^1;
sbit IN1=P1^0;
sbit IN2=P1^1;
void delay(unsigned int z);
void run(void)
{
IN1=0;
IN2=1;
}
void stop(void)
{
IN1=0;
IN2=0;
}
void back(void)
{
IN1=1;
IN2=0;
}
void main(void)
{
uchar flag=0;
P2=0x08;
while(1)
{
if(D1==1)
{
if(D1==1)
{
flag++;
if(flag==3)
{
flag=0;
}
while(D1);
}
switch(flag)
{
case 1:
back();
D1=0;
delay(5000);
stop();
break;
case 2:
back();
D1=0;
break;
}
}
if(D2==1)
{
if(D2==1)
{
flag++;
if(flag==3)
{
flag=0;
}
while(D2);
}
switch(flag)
{
case 1:
run();
D2=0;
delay(5000);
stop();
break;
case 2:
run();
D2=0;
break;
}
}
if(K1==0||K2==0)
{
stop();
}
if(D0==1)
{
while(D0==1)
{
stop() ;
}
}
}
}
void delay(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
|