下面是我寫(xiě)的步進(jìn)電機(jī)程序。我細(xì)分裝置設(shè)置的是4000,下面應(yīng)該會(huì)有3200個(gè)脈沖,也就是會(huì)旋轉(zhuǎn)0.8周,實(shí)際運(yùn)行后并沒(méi)有0.8周這么多;后來(lái)我將程序兩個(gè)循環(huán)a>=0,和i>=0;發(fā)現(xiàn)電機(jī)運(yùn)動(dòng)停不下來(lái),我想知道是怎么回事?謝謝
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit zmc=P1^0;
sbit fmc=P1^1;
sbit zfx=P1^2;
sbit ffx=P1^3;
void delay5ws(uchar);
void main()
{
uint i,a;
i=0;
a=0;
zmc=0;
fmc=0;
zfx=0;
ffx=0;
delay5ws(5);
zfx=1;
for(a=80;a>0;a--)
{
for(i=40;i>0;i--)
{
// delay5ws(5);
zmc=1;
// delay5ws(2);
zmc=0;
}
}
while(1)
{
zmc=0;
fmc=0;
zfx=0;
ffx=0;
}
}
void delay5ws(uchar n)
{
uint l,m;
for(l=n;l>0;l--)
for(m=2;m>0;m--);
}