高级会员
- 积分
- 604
- 威望
- 341
- 贡献
- 187
- 兑换币
- 162
- 注册时间
- 2012-6-30
- 在线时间
- 38 小时
|
3#
楼主 |
发表于 2014-6-12 12:06:28
|
只看该作者
/****************************************************************************
* motor_update(char channel, char dir) -
*
* Description : Control motor drivers and polarity
* :
* Example : N/A
* Input : motor channel
* Output : MotorCurStyep[?]
* Modify : Motor driver and polarity
* Return : N/A
****************************************************************************/
void motor_update(char channel) //分步方式步进电机刷新程序
{
volatile unsigned char ctemp,*motor_channel;
int temp,itemp;
itemp=MotorFinalStep[channel]-MotorCurStep[channel];//目标步数值减去了当前步数值
if (itemp!=0)
{
if (itemp<0) MotorCurStep[channel]--;
else if (itemp>0) MotorCurStep[channel]++;
//motor_channel=&MCDC0H+channel*4;
motor_channel=(unsigned char *)((unsigned int)&MCDC0 + (unsigned int)(channel*4));
temp = MotorCurStep[channel];
asm {
ldd temp; // 带偏移量的间接寻址装载指令
ldx #4
idiv // 有符号数除法指令IDIV
stab ctemp
}
if(ctemp==0)
{
*motor_channel &=~S0_DTC; //;Duty cycle channel 0 (A low /A PWM)
*(motor_channel+2) &=~S0_DTC; //;Duty cycle channel 1 (B low /B PWM)
}
else if(ctemp==1)
{
*motor_channel &=~S0_DTC; //;Duty cycle channel 0 (A low /A PWM)
*(motor_channel+2) |=S1_DTC; //;Duty cycle channel 1 (B PWM /B low)
}
else if(ctemp==2)
{
*motor_channel |=S1_DTC; //;Duty cycle channel 0 (A PWM /A low)
*(motor_channel+2) |=S1_DTC; //;Duty cycle channel 1 (B PWM /B low)
}
else if(ctemp==3)
{
*motor_channel |=S1_DTC; //;Duty cycle channel 0 (A PWM /A low)
*(motor_channel+2) &=~S0_DTC; //;Duty cycle channel 1 (B low /B PWM)
}
}
else
{
MotorStatus[channel]=OFF;
}
} |
|