I find a program for running 4-phrase stepping motor module 42H2P4412A4 using
8051 MCUdevelopment board,But I didn't understand part of them. The following
is the programme:
#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(); //步進電機運行
}
}
I don't understand why the programmer define i as char, not int. Also, can you tell me the function of TableA and TableB in the programme ie: Reason for defining
the 2 tables and reason for using it.
Thanks