单片机通过驱动器驱动步进电机,求大神指导?
程序:#include<reg51.h>sbitpulse=P2^7;sbitdirect=P2^3;sbitK0=P0^0;unsignedintdisplacemen...
程序:
#include <reg51.h>
sbit pulse = P2^7;
sbit direct = P2^3;
sbit K0 = P0^0;
unsigned int displacement = 22; //所需要的位移量/mm
unsigned int speed = 10; //速度量/mm/s
unsigned int subdivide = 8; //驱动细分数
unsigned int step_count; //记步数
unsigned int step ;
unsigned char TH_0;
unsigned char TL_0;
void main()
{
P2=0xdc;
IE = 0x82;
TMOD = 0x01;
step = displacement * 25 * 8;
TH_0 = (65536 - 500000 / (speed * 25 * subdivide))/256;
TL_0 = (65536 - 500000 / (speed * 25 * subdivide))%256;
step_count = 0;
TH0 = TH_0;
TL0 = TL_0;
while(1)
{
if(K0 == 0)
{
TF0 = 0;
TR0 = 1;
}
else
TR0 = 0;
}
}
void timer0 (void) interrupt 1
{
TR0 = 0;
TH0 = TH_0;
TL0 = TL_0;
pulse = ~pulse;
step_count++;
if(step_count>=step)
{direct = ~direct;step_count = 0;}
TR0 = 1;
}
我将方向+方向-脱机+脱机-脉冲+脉冲-一次连接在P2~P7口,按下键盘时,步进电机竟然没有动,哪位大神可以指导一下呀?不胜感激。。。 展开
#include <reg51.h>
sbit pulse = P2^7;
sbit direct = P2^3;
sbit K0 = P0^0;
unsigned int displacement = 22; //所需要的位移量/mm
unsigned int speed = 10; //速度量/mm/s
unsigned int subdivide = 8; //驱动细分数
unsigned int step_count; //记步数
unsigned int step ;
unsigned char TH_0;
unsigned char TL_0;
void main()
{
P2=0xdc;
IE = 0x82;
TMOD = 0x01;
step = displacement * 25 * 8;
TH_0 = (65536 - 500000 / (speed * 25 * subdivide))/256;
TL_0 = (65536 - 500000 / (speed * 25 * subdivide))%256;
step_count = 0;
TH0 = TH_0;
TL0 = TL_0;
while(1)
{
if(K0 == 0)
{
TF0 = 0;
TR0 = 1;
}
else
TR0 = 0;
}
}
void timer0 (void) interrupt 1
{
TR0 = 0;
TH0 = TH_0;
TL0 = TL_0;
pulse = ~pulse;
step_count++;
if(step_count>=step)
{direct = ~direct;step_count = 0;}
TR0 = 1;
}
我将方向+方向-脱机+脱机-脉冲+脉冲-一次连接在P2~P7口,按下键盘时,步进电机竟然没有动,哪位大神可以指导一下呀?不胜感激。。。 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询