仿真图:
仿真程序:
#include
uchar code zz[]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09}; uchar code fz[]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};
void delay(uint ms) { uint t; while(ms--)
for(t=0;t<120;t++);
}
void motor_zz(uint n) { uint i,j;
for(i=0;i<5*n;i++) { for(j=0;j<8;j++) { if(P3==0xfb)
break; P1=zz[j]; delay(20);
}
}
}
void motor_fz(uint n) { uint i,j;
for(i=0;i<5*n;i++)
{ //正转 //反转
}
}
for(j=0;j<8;j++) { }
if(P3==0xfb)
break; P1=fz[j]; delay(20);
void main() {
uint N=3; while(1) {
P3=0xff; if(P3==0xfe) { }
else if(P3==0xfd) { } else {
P0=0xfb; while(P3==0xfd); P0=0xfd; motor_fz(N); if(P3==0xfb)
break; while(P3==0xfe); P0=0xfe; motor_zz(N); if(P3==0xfb)
break;
}
}
}
P1=0x03;