#include
//**********************正向旋转相序表***************************** unsigned char code FFW[8]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};
//**********************反向旋转相序表*****************************
unsigned char code REV[8]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};
//***********************延时子程序********************************
void delay(unsigned int t)
{ unsigned int k; while(t--) {
for(k=0; k<125; k++) {} } }
//**********************步进电机正转******************************
void motor_ffw(unsigned int n) {
unsigned char i; unsigned int j;
for (j=0; j<8*64*n; j++) {
for (i=0; i<8; i++) {
P1 = FFW[i]; delay(1); } } }
//*********************步进电机反转********************************
void motor_rev(unsigned int n) {
unsigned char i; unsigned int j;
for (j=0; j<8*64*n; j++) {
for (i=0; i<8; i++) {
P1 = REV[i]; delay(1); } } }
//*************************主程序********************************* main() {
while(1) {
motor_ffw(5); //电机正转5圈 delay(1000);
motor_rev(5); //电机反转5圈 delay(1000);
} }