|
刚刚接触步进电机,型号为28byj-48,驱动芯片是ULN2003,现在发现正转角度正常,反转角度不准,求坛子里搞过步进电机的大神们指点
#include<reg52.h>
unsigned long beats=0;
unsigned char code beatcode_p[8]= //正转
{0x01,0x03,0x02,0x06,0x04,0xc0,0x08,0x09};
unsigned char code beatcode_n[8]= //反转
{0x09,0x08,0xc0,0x04,0x06,0x02,0x03,0x01};
void trunmotor(unsigned long angle);
void main()
{
TMOD=0x01;
TH0=0xf8;
TL0=0xcd;
TR0=1;
ET0=1;
EA=1;
trunmotor(360*2+180); //两圈半
while(1);
}
void trunmotor(unsigned long angle)
{
EA=0;
beats=(angle*4076)/360; //计算所需的脉冲个数
EA=1;
}
void interrupttime0() interrupt 1
{
static unsigned char step=0;
TH0=0xf8;
TL0=0xcd;
if(beats!=0)
{
P1=beatcode_p[step];
step++;
if(step==8) step=0;
beats--;
}
else
{
P1|=0x0f; //关闭脉冲输出
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|