还请各位大虾帮忙看看程序,控制3个电机转动的,但为什么,只有其中的一个能动呢,帮忙看看啊.
/************************************************************/
/* x y s 轴转动
/*bu_x bu_y bu_s xys_fp dl
/*x最大步数 y最大步数 s最大步数 xys轴减速倍数 延时倍数
/*x_fp=2时,X转速=原速/1.5 , x_fp=3时,X转速=原速/2
/************************************************************/
void siba_xys(int bu_x,int bu_y,int bu_s,uchar x_fp,uchar y_fp,uchar s_fp,uint dl)
{
uchar xfp,yfp,sfp;
if(x_fp==0)x_fp=1;
if(y_fp==0)y_fp=1;
if(s_fp==0)s_fp=1;
xfp="x"_fp;yfp=y_fp;sfp=s_fp;
while(bu_x|bu_y|bu_s)
{
/////////////////////////////////////////////// x ( P0 低4位 )
if(bu_x!=0)
{
xfp--;
if(xfp==0)
{
if(bu_x>0) ///正转
{
if(x_sd==0) siba_x01=siba_x01<<1; else siba_x02=siba_x02<<1;
if(siba_x01==0x10) siba_x01=0x01;
if(siba_x02==0x10) siba_x02=0x01;
x_sd=~x_sd; //单双相选择标志
bu_x--;
}
if(bu_x<0) ///反转
{
if(x_sd==0)siba_x02=siba_x02>>1; else siba_x01=siba_x01>>1;
if(siba_x01==0x0) siba_x01=0x08;
if(siba_x02==0x0) siba_x02=0x08;
x_sd=~x_sd; //单双相选择标志
bu_x++;
}
xfp="x"_fp;
}
}
/////////////////////////////////////////////// y ( P0 高四位 )
if(bu_y!=0)
{
yfp--;
if(yfp==0)
{
if(bu_y>0) ///正转
{
if(y_sd==0)siba_y01=siba_y01<<1; else siba_y02=siba_y02<<1;
if(siba_y01==0x0) siba_y01=0x10;
if(siba_y02==0x0) siba_y02=0x10;
y_sd=~y_sd; //单双相选择标志
bu_y--;
}
if(bu_y<0) ///反转
{
if(y_sd==0) siba_y01=siba_y01>>1;else siba_y02=siba_y02>>1;
if(siba_y01==0x08) siba_y01=0x80;
if(siba_y02==0x08)siba_y02=0x80;
y_sd=~y_sd; //单双相选择标志
bu_y++;
}
yfp="y"_fp;
}
}
/////////////////////////////////////////////// s ( P2 高四位 )
if(bu_s!=0)
{
sfp--;
if(sfp==0)
{
if(bu_s>0) ///正转
{
if(s_sd==0)siba_s01=siba_s01<<1; else siba_s02=siba_s02<<1;
if(siba_s01==0x0) siba_s01=0x10;
if(siba_s02==0x0) siba_s02=0x10;
s_sd=~s_sd; //单双相选择标志
bu_s--;
}
if(bu_s<0) ///反转
{
if(s_sd==0)siba_s02=siba_s02>>1; else siba_s01=siba_s01>>1;
if(siba_s01==0x08) siba_s01=0x80;
if(siba_s02==0x08) siba_s02=0x80;
s_sd=~s_sd; //单双相选择标志
bu_s++;
}
sfp="s"_fp;
}
}
//////////////////////////////////////////////////
mada_xy=siba_x01|siba_x02|siba_y01|siba_y02; //P0
mada_s=siba_s01|siba_s02; //P2
delay01(dl); //调用时,没有 "参数" 会出错~~~~
}
文章评论(0条评论)
登录后参与讨论