仿真图:仿真程序:#includereg52.h#defineuintunsignedint#defineucharunsignedchar//------8拍-----ucharcodezz[]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};//正转ucharcodefz[]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};//反转voiddelay(uintms){uintt;while(ms--)for(t=0;t120;t++);}voidmotor_zz(uintn){uinti,j;for(i=0;i5*n;i++){for(j=0;j8;j++){if(P3==0xfb)break;P1=zz[j];delay(20);}}}voidmotor_fz(uintn){uinti,j;for(i=0;i5*n;i++){for(j=0;j8;j++){if(P3==0xfb)break;P1=fz[j];delay(20);}}}voidmain(){uintN=3;while(1){P3=0xff;if(P3==0xfe){while(P3==0xfe);P0=0xfe;motor_zz(N);if(P3==0xfb)break;}elseif(P3==0xfd){while(P3==0xfd);P0=0xfd;motor_fz(N);if(P3==0xfb)break;}else{P0=0xfb;P1=0x03;}}}