|
资料里的程序是这样的
#include "reg52.h"
#define speed 38
//Motor
sbit PH1 = P1^0; //定义管脚
sbit PH2 = P1^1;
sbit I01 = P1^2;
sbit I11 = P1^3;
sbit I02 = P1^4;
sbit I12 = P1^5;
unsigned char TableA[] = { 0XF7,0XFB,0XF3}; //A线圈细分表
unsigned char TableB[] = { 0XeF,0XdF,0XcF}; //B线圈细分表
void delay(int time);
/***************************************
函数功能:产生单相四拍脉冲控制步进机 2细分
**************************************/
void Go()
{ char i ,temp;
//A
PH1 = 0; //PH1为0 则A线圈为反向电流
for(i = 0; i<3; i++)
{ temp = P1;
P1 = TableA[i];
P1 = P1&temp;
delay(1);
}
PH2 = 0; //PH2为0 则B线圈为反向电流
I02 = 1;
I12 = 1; //输出0
delay(speed);
//0
PH1 = 0; //PH1为0 则A线圈为反向电流
I01 = 1; //输出0
I11 = 1;
PH2 = 1; //PH2为1 则B线圈为正电流
for(i = 0; i<3; i++)
{ temp = P1;
P1 = TableB[i];
P1 = P1&temp;
delay(1);
}
delay(speed);
//B
PH1 = 1; //PH1为1 则A线圈为正向电流
for(i = 0; i<3; i++)
{ temp = P1;
P1 = TableA[i];
P1 = P1&temp;
delay(1);
}
PH2 = 1; //PH2为1 则B线圈为正向电流
I02 = 1; //输出0
I12 = 1;
////
delay(speed);
//0
PH1 = 1; //PH1为1 则A线圈为正向电流
I01 = 1;
I11 = 1;
PH2 = 0; //PH2为0 则B线圈为反向电流
for(i = 0; i<3; i++)
{ temp = P1;
P1 = TableB[i];
P1 = P1&temp;
delay(1);
}
delay(speed);
}
/*******************延时函数****************************/
void delay(int time)
{
int i,j;
for(j=0; j <= time; j++)
for(i =0 ; i <= 120; i++);
}
void main()
{
while(1)
{
Go(); //步进电机运行
}
}
求解
unsigned char TableA[] = { 0XF7,0XFB,0XF3}; //A线圈细分表
unsigned char TableB[] = { 0XeF,0XdF,0XcF}; //B线圈细分表
这两个数组是怎么得来的,如果要512细分或者256细分,又该怎样写? |
|