#includereg51.h#includeintrins.h//**********************正向旋转相序表*****************************unsignedcharcodeFFW[8]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};//**********************反向旋转相序表*****************************unsignedcharcodeREV[8]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};//***********************延时子程序********************************voiddelay(unsignedintt){unsignedintk;while(t--){for(k=0;k125;k++){}}}//**********************步进电机正转******************************voidmotor_ffw(unsignedintn){unsignedchari;unsignedintj;for(j=0;j8*64*n;j++){for(i=0;i8;i++){P1=FFW[i];delay(1);}}}//*********************步进电机反转********************************voidmotor_rev(unsignedintn){unsignedchari;unsignedintj;for(j=0;j8*64*n;j++){for(i=0;i8;i++){P1=REV[i];delay(1);}}}//*************************主程序*********************************main(){while(1){motor_ffw(5);//电机正转5圈delay(1000);motor_rev(5);//电机反转5圈delay(1000);}}