|
所用:單片機(jī)STC89C52、42步進(jìn)電機(jī)、驅(qū)動(dòng)器L298N
兩個(gè)步進(jìn)電機(jī):電機(jī)1由P1.0~P1.3控制,電機(jī)2由P1.4~P1.7控制。
運(yùn)行結(jié)果:電機(jī)軸來回?cái)[動(dòng),轉(zhuǎn)得極慢(電機(jī)1更慢)。程序錯(cuò)在哪里?為什么會(huì)擺動(dòng)?望指教!
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code upa_data[8]={ 0xf9,0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8};
uchar code upb_data[8]={ 0x9f,0x1f,0x3f,0x2f,0x6f,0x4f,0xcf,0x8f};
/********以下是延時(shí)函數(shù)********/
void Delay(uint speed)
{
uint i,j;
for(i=speed;i>0;i--)
for(j=110;j>0;j--); //大約1毫秒,
}
/********以下是主函數(shù)********/
void main()
{
uint count=400;
while(count!=0x00)
{
uchar i;
for (i=0; i<8; i++)
{
P1 = upa_data;
Delay(50);
P1 = upb_data;
Delay(50);
}
}
}
|
|