步进电机为四相八拍模式,为什么要66拍才转了1圈,而不是64拍?
#include <reg52.h>
unsigned long beats=0;
void StartMotor(unsigned long angle);
void main()
{
EA=1;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
TR0=1;
StartMotor(360);
while(1);
}
void StartMotor(unsigned long angle)
{
EA=0;
beats=(angle*66)/360; //66拍
EA=1;
}
void InterruptTimer0() interrupt 1
{
static unsigned char index=0;
unsigned char tmp;
unsigned char code BeatChar[]={0x0e,0x0c,0x0d,0x09,0x0b,0x03,0x07,0x06};
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(beats!=0)
{
tmp=P1;
tmp=tmp&0xf0;
tmp=tmp|BeatChar[index];
P1=tmp;
index++;
index=index&0x07;
beats--;
}
else
{
P1=P1|0x0f;
}
}
|