我用的是28BYJ-48型号的步进电机,用ULN2003芯片驱动,接P1口低四位,只看到它顺时针转,却没办法让他逆时针转 ,程序如下:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar f_rotation[]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};
uchar b_rotation[]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};
void delay(uint i)
{
uchar x;
for(;i>0;i--)
for(x=200;x>0;x--);
}
void main()
{
uchar i;
while(1)
{
for(i=0;i<8;i--) //四相八拍
{
P1=b_rotation[i];
delay(500);
}
for(i=0;i<8;i--)
{
P1=f_rotation[i];
delay(500);
}
}
}
求教 |