单片机控制2轮电机,红色部分显示错误
#include<reg52.h>
#define Lg {P1^4=1,P1^5=0,P1^6=1,P1^7=0;} //左边2个电机前是前电机
#define Lb{P1^4=0,P1^5=1,P1^6=0,P1^7=1;} //左后
#define Ls {P1^4=0,P1^5=0,P1^6=0,P1^7=0;}
#define Rg {P1^4=1, P1^5=1,P1^6=1, P1^7=1;}
#define Rb {P1^4=0,P1^5=0,P1^6=0,P1^7=1;}
#define Rs {P1^4=0,P1^5=0,P1^6=0,P1^7=0;}
sbit S1=P1^4 ;
sbit S2=P1^5 ;
sbit S3=P1^6 ;
sbit S4=P1^7 ;
sbit S5=P1^4 ;
sbit S6=P0^7;
sbit S16=P0^6 ;
sbit S15=P0^5;
sbit S14=P0^4 ;
void delay(unsigned int k)
{
unsigned int x,y;
for(x=0;x<k;x++);
for(y=0;y<2000;y++);
}
void run(void)
{
Lg;
Rg;
}
void backrun(void)
{
Lb;
Rb;
}
void leftrun(void)
{
Lb;
Rg;
}
void rightrun(void)
{
Lg;
Rb;
}
void stoprun(void)
{
Ls;
Rs;
}
void main(void)
{
while(1)
{
if(P0^7==1&&P0^6==0)
{run(); }
if(P0^6==1&&P0^7==0)
{backrun();}
if(P0^5==1)
{leftrun();}
if(P0^4==1)
{rightrun(); }
if(P0^7==1&&P0^6==1)
{
stoprun();
}
那个宏定义中可以用总线赋值试下,如P1=0x01