需要写个想超市电动门一样的code
int main (void)
{
{
TRISD=0;
TRISB=1;
unsigned int i;
while (1)
if ((RB4==1) ||(RB5==1)) //RB4=motion sensor and RB5=door fully closed
{
i=1;
}
else if (RB2==1) //rb2=door fully open 1
{
i=0;
}
while ((i==1) && (RB2==0)) //rb2=door fully open 0
{
RD3=1; //motor door open
}
RD3=0;
while ((i==0)&&(RB5==0)) //RB0=doorclosed
{
RD2=1; //motor door close
}
RD2=0;
}
}
return (0);
}
问题是当第2个while loop出不来了一直在RD2=1, 当RB5=1马达就不动了,放开就继续转。我希望的是能回到第一行的if RB4在给个1 继续在loop 一般。新手请大家指教指教 |