所用:單片機STC89C52、42步進電機、驅動器L298N
兩個步進電機:電機1由P1.0~P1.3控制,電機2由P1.4~P1.7控制。
運行結果:電機軸來回擺動,轉得極慢(電機1更慢)。程序錯在哪里?為什么會擺動?望指教!
#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};
/********以下是延時函數********/
void Delay(uint speed)
{
uint i,j;
for(i=speed;i>0;i--)
for(j=110;j>0;j--); //大約1毫秒,
}
/********以下是主函數********/
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);
}
}
}
|