📄 main.c
字号:
tmpptr = (BYTE idata*)&MotorStatus[0].TotalPluseCnt + LSB;
if ( DIR0 )
DWordDec( );
else
DWordInc( );
// 当前脉冲减
tmpptr = (BYTE idata*)&Timer[0].CurPluseNum + LSB;
DWordDec( );
// 零位检测
if ( MotorStatus[0].Status & ZERO_CHECK_MASK )
{
// 零位到达
if ( !LastTimer0ST && ST0 )
{
MotorStatus[0].Status |= MOTOR_STOP_CMD_MASK;
MotorStatus[0].Status |= ZERO_RECORD_MASK;
MotorStatus[0].TotalPluseCnt = 0;
break;
}
LastTimer0ST = ST0;
}
// 脉冲数未完
if ( Timer[0].CurPluseNum )
break;
if ( (MotorStatus[0].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
{
DIR0 = ~DIR0;
Timer[0].CurPluseNum = MotorStatus[0].CmdPluseNum;
}
else
{
// 停止
MotorStatus[0].Status |= MOTOR_STOP_CMD_MASK;
}
break;
// 电机1
case 2:
if ( MotorStatus[1].Status & MOTOR_STOP_CMD_MASK )
{
if ( (MotorStatus[1].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
{
if ( Timer[0].CenrerPluse == (WORD)MotorStatus[1].TotalPluseCnt )
{
// 只保留零点记录标志
MotorStatus[1].Status &= ZERO_RECORD_MASK;
MotorStatus[1].Dir = 0;
// 关定时器0
TR0 = 0;
ET0 = 0;
Timer[0].MotorIdx = 0;
break;
}
}
else
{
// 只保留零点记录标志
MotorStatus[1].Status &= ZERO_RECORD_MASK;
MotorStatus[1].Dir = 0;
// 关定时器0
TR0 = 0;
ET0 = 0;
Timer[0].MotorIdx = 0;
PUL1 = 1;
break;
}
}
// 改变输出电平
PUL1 = ~PUL1;
// 增减脉冲总数量
tmpptr = (BYTE idata*)&MotorStatus[1].TotalPluseCnt + LSB;
if ( DIR1 )
DWordDec( );
else
DWordInc( );
// 当前脉冲减
tmpptr = (BYTE idata*)&Timer[0].CurPluseNum + LSB;
DWordDec( );
// 零位检测
if ( MotorStatus[1].Status & ZERO_CHECK_MASK )
{
// 零位到达
if ( !LastTimer0ST && ST1 )
{
MotorStatus[1].Status |= MOTOR_STOP_CMD_MASK;
MotorStatus[1].Status |= ZERO_RECORD_MASK;
MotorStatus[1].TotalPluseCnt = 0;
break;
}
LastTimer0ST = ST1;
}
// 脉冲数未完
if ( Timer[0].CurPluseNum )
break;
if ( (MotorStatus[1].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
{
DIR1 = ~DIR1;
Timer[0].CurPluseNum = MotorStatus[1].CmdPluseNum;
}
else
{
// 停止
MotorStatus[1].Status |= MOTOR_STOP_CMD_MASK;
}
break;
// 电机2
case 3:
if ( MotorStatus[2].Status & MOTOR_STOP_CMD_MASK )
{
if ( (MotorStatus[2].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
{
if ( Timer[0].CenrerPluse == (WORD)MotorStatus[2].TotalPluseCnt )
{
// 只保留零点记录标志
MotorStatus[2].Status &= ZERO_RECORD_MASK;
MotorStatus[2].Dir = 0;
// 关定时器0
TR0 = 0;
ET0 = 0;
Timer[0].MotorIdx = 0;
break;
}
}
else
{
// 只保留零点记录标志
MotorStatus[2].Status &= ZERO_RECORD_MASK;
MotorStatus[2].Dir = 0;
// 关定时器0
TR0 = 0;
ET0 = 0;
Timer[0].MotorIdx = 0;
PUL2 = 1;
break;
}
}
// 改变输出电平
PUL2 = ~PUL2;
// 增减脉冲总数量
tmpptr = (BYTE idata*)&MotorStatus[2].TotalPluseCnt + LSB;
if ( DIR2 )
DWordDec( );
else
DWordInc( );
// 当前脉冲减
tmpptr = (BYTE idata*)&Timer[0].CurPluseNum + LSB;
DWordDec( );
// 零位检测
if ( MotorStatus[2].Status & ZERO_CHECK_MASK )
{
// 零位到达
if ( !LastTimer0ST && ST2 )
{
MotorStatus[2].Status |= MOTOR_STOP_CMD_MASK;
MotorStatus[2].Status |= ZERO_RECORD_MASK;
MotorStatus[2].TotalPluseCnt = 0;
break;
}
LastTimer0ST = ST2;
}
#if (SCH_PCB_VERSION == 1)
// 工作零位检测
if ( MotorStatus[2].Status & WORK_ZERO_CHECK_MASK )
{
// 零位到达
if ( !LastTimer0WST && WST2 )
{
MotorStatus[2].Status |= MOTOR_STOP_CMD_MASK;
break;
}
LastTimer0WST = WST2;
}
#endif
// 脉冲数未完
if ( Timer[0].CurPluseNum )
break;
if ( (MotorStatus[2].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
{
DIR2 = ~DIR2;
Timer[0].CurPluseNum = MotorStatus[2].CmdPluseNum;
}
else
{
// 停止
MotorStatus[2].Status |= MOTOR_STOP_CMD_MASK;
}
break;
// 电机3
case 4:
if ( MotorStatus[3].Status & MOTOR_STOP_CMD_MASK )
{
if ( (MotorStatus[3].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
{
if ( Timer[0].CenrerPluse == (WORD)MotorStatus[3].TotalPluseCnt )
{
// 只保留零点记录标志
MotorStatus[3].Status &= ZERO_RECORD_MASK;
MotorStatus[3].Dir = 0;
// 关定时器0
TR0 = 0;
ET0 = 0;
Timer[0].MotorIdx = 0;
break;
}
}
else
{
// 只保留零点记录标志
MotorStatus[3].Status &= ZERO_RECORD_MASK;
MotorStatus[3].Dir = 0;
// 关定时器0
TR0 = 0;
ET0 = 0;
Timer[0].MotorIdx = 0;
PUL3 = 1;
break;
}
}
// 改变输出电平
PUL3 = ~PUL3;
// 增减脉冲总数量
tmpptr = (BYTE idata*)&MotorStatus[3].TotalPluseCnt + LSB;
if ( DIR3 )
DWordDec( );
else
DWordInc( );
// 当前脉冲减
tmpptr = (BYTE idata*)&Timer[0].CurPluseNum + LSB;
DWordDec( );
// 零位检测
if ( MotorStatus[3].Status & ZERO_CHECK_MASK )
{
// 零位到达
if ( !LastTimer0ST && ST3 )
{
MotorStatus[3].Status |= MOTOR_STOP_CMD_MASK;
MotorStatus[3].Status |= ZERO_RECORD_MASK;
MotorStatus[3].TotalPluseCnt = 0;
break;
}
LastTimer0ST = ST3;
}
// 脉冲数未完
if ( Timer[0].CurPluseNum )
break;
if ( (MotorStatus[3].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
{
DIR3 = ~DIR3;
Timer[0].CurPluseNum = MotorStatus[3].CmdPluseNum;
}
else
{
// 停止
MotorStatus[3].Status |= MOTOR_STOP_CMD_MASK;
}
break;
// 电机4
case 5:
if ( MotorStatus[4].Status & MOTOR_STOP_CMD_MASK )
{
if ( (MotorStatus[4].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
{
if ( Timer[0].CenrerPluse == (WORD)MotorStatus[4].TotalPluseCnt )
{
// 只保留零点记录标志
MotorStatus[4].Status &= ZERO_RECORD_MASK;
MotorStatus[4].Dir = 0;
// 关定时器0
TR0 = 0;
ET0 = 0;
Timer[0].MotorIdx = 0;
break;
}
}
else
{
// 只保留零点记录标志
MotorStatus[4].Status &= ZERO_RECORD_MASK;
MotorStatus[4].Dir = 0;
// 关定时器0
TR0 = 0;
ET0 = 0;
Timer[0].MotorIdx = 0;
PUL4 = 1;
break;
}
}
// 改变输出电平
PUL4 = ~PUL4;
// 增减脉冲总数量
tmpptr = (BYTE idata*)&MotorStatus[4].TotalPluseCnt + LSB;
if ( DIR4 )
DWordDec( );
else
DWordInc( );
// 当前脉冲减
tmpptr = (BYTE idata*)&Timer[0].CurPluseNum + LSB;
DWordDec( );
// 零位检测
if ( MotorStatus[4].Status & ZERO_CHECK_MASK )
{
// 零位到达
if ( !LastTimer0ST && ST4 )
{
MotorStatus[4].Status |= MOTOR_STOP_CMD_MASK;
MotorStatus[4].Status |= ZERO_RECORD_MASK;
MotorStatus[4].TotalPluseCnt = 0;
break;
}
LastTimer0ST = ST4;
}
// 脉冲数未完
if ( Timer[0].CurPluseNum )
break;
if ( (MotorStatus[4].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
{
DIR4 = ~DIR4;
Timer[0].CurPluseNum = MotorStatus[4].CmdPluseNum;
}
else
{
// 停止
MotorStatus[4].Status |= MOTOR_STOP_CMD_MASK;
}
break;
// 电机5
case 6:
if ( MotorStatus[5].Status & MOTOR_STOP_CMD_MASK )
{
if ( (MotorStatus[5].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
{
if ( Timer[0].CenrerPluse == (WORD)MotorStatus[5].TotalPluseCnt )
{
// 只保留零点记录标志
MotorStatus[5].Status &= ZERO_RECORD_MASK;
MotorStatus[5].Dir = 0;
// 关定时器0
TR0 = 0;
ET0 = 0;
Timer[0].MotorIdx = 0;
break;
}
}
else
{
// 只保留零点记录标志
MotorStatus[5].Status &= ZERO_RECORD_MASK;
MotorStatus[5].Dir = 0;
// 关定时器0
TR0 = 0;
ET0 = 0;
Timer[0].MotorIdx = 0;
PUL5 = 1;
break;
}
}
// 改变输出电平
PUL5 = ~PUL5;
// 增减脉冲总数量
tmpptr = (BYTE idata*)&MotorStatus[5].TotalPluseCnt + LSB;
if ( DIR5 )
DWordDec( );
else
DWordInc( );
// 当前脉冲减
tmpptr = (BYTE idata*)&Timer[0].CurPluseNum + LSB;
DWordDec( );
// 零位检测
if ( MotorStatus[5].Status & ZERO_CHECK_MASK )
{
// 零位到达
if ( !LastTimer0ST && ST5 )
{
MotorStatus[5].Status |= MOTOR_STOP_CMD_MASK;
MotorStatus[5].Status |= ZERO_RECORD_MASK;
MotorStatus[5].TotalPluseCnt = 0;
break;
}
LastTimer0ST = ST5;
}
#if (SCH_PCB_VERSION == 1)
// 工作零位检测
if ( MotorStatus[5].Status & WORK_ZERO_CHECK_MASK )
{
// 零位到达
if ( !LastTimer0WST && WST5 )
{
MotorStatus[5].Status |= MOTOR_STOP_CMD_MASK;
break;
}
LastTimer0WST = WST5;
}
#endif
// 脉冲数未完
if ( Timer[0].CurPluseNum )
break;
if ( (MotorStatus[5].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
{
DIR5 = ~DIR5;
Timer[0].CurPluseNum = MotorStatus[5].CmdPluseNum;
}
else
{
// 停止
MotorStatus[5].Status |= MOTOR_STOP_CMD_MASK;
}
break;
}
}
void timer_1(void) interrupt 3 using 2
{
TimerEndTmpFlag = 0;
if ( Timer1EndIntFlag )
{
Timer[1].IntCnt = 0;
TimerEndTmpFlag = 1;
if ( Timer[1].SecConstFlag )
{
Timer[1].TimerConstCntH = Timer[1].SecTimerConstCntH;
Timer[1].TimerConstH = Timer[1].SecTimerConstH;
Timer[1].TimerConstL = Timer[1].SecTimerConstL;
Timer[1].SecConstFlag = 0;
}
}
TR1 = 0;
if ( Timer[1].IntCnt == Timer[1].TimerConstCntH )
{
Timer1EndIntFlag = 1;
TL1 += Timer[1].TimerConstL;
TH1 = Timer[1].TimerConstH;
}
else
{
Timer1EndIntFlag = 0;
}
TR1 = 1;
Timer[1].IntCnt++;
if ( !TimerEndTmpFlag )
return;
if ( Timer[1].UpDwonCnt )
Timer[1].UpDwonCnt--;
switch( Timer[1].MotorIdx )
{
// 电机0
case 1:
if ( MotorStatus[0].Status & MOTOR_STOP_CMD_MASK )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -