各位看官,下面的这段代码是步进电机驱动代码,看看有什么错误,如果有错误会产生什么后果?注:改变方向的代码被省略了。
如有不爽,欢迎各种拍砖,**蛋,瓜子皮,西瓜皮... ...
#include "reg52.h"
sbit A = P1^4; //定义管脚
sbit B = P1^5;
sbit C = P1^6;
sbit D = P1^7;
bit a;
#define fwd a=1 //正向
#define rev a=0 //逆向
#define round 8
#define delay 500
unsigned char code run[]={0xEF,0xCF,0xDF,0x9F,0xBF,0x3F,0x7F,0x6F};//运行相序表
void play(unsigned char x)
{
unsigned int i;
P1 = P1 & run[x];
for(i=0; i<delay; i++);
}
void main()
{
unsigned char d;
while(1)
{
if(fwd)
{
for(d=0;d<round;d++)
play(d);
}else{
for(d=round;d>0;d--)
play(d);
}
}
} |