为什么我这程序驱动步进电机的时候,电机会顿。转的不匀。。
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit IN1=P0^0;
sbit IN2=P0^1;
sbit IN3=P0^2;
sbit IN4=P0^3;
sbit ENA=P3^0;
sbit ENB=P3^1;
void delayt(uint z);
unsigned char A[8]={0x01,0x05,0x04,0x06,0x02,0x0a,0x08,0x09};
//unsigned char C[4]={0x01,0x04,0x02,0x08};
void dianjixuanzhuan(long int pulse,uchar zf,uchar t)//角度。方向。延时
{
long int b;
int i=0;
for(b=0;b<=pulse;b++)
{
P0=A[i];
delayt(t);
if(zf==0)
{
if(i==7)
i=0;
else
i++;
}
else
{
if(i==0)
i=7;
else
i--;
}
}
//P1=0X00;
//while(1);
}
void delayt(uint z)
{
uint x, y;
for(x=z;x>0;x--);
for(y=220;y>0;y--);
}
void main()
{
uint a;
ENA = 0;
ENB = 0;
for(a=5;a>0;a--)
{dianjixuanzhuan(100,1,2);}
} |