⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 基于RS232的键盘,也可以作为输入输出的操作面板,用于数控系统开发
💻 C
📖 第 1 页 / 共 3 页
字号:
			{
				if ( (MotorStatus[0].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
				{
					if ( Timer[1].CenrerPluse == (WORD)MotorStatus[0].TotalPluseCnt )
					{
						// 只保留零点记录标志
						MotorStatus[0].Status &= ZERO_RECORD_MASK;	
						MotorStatus[0].Dir = 0;

						// 关定时器0
						TR1 = 0;
						ET1 = 0;
						Timer[1].MotorIdx = 0;
						break;
					}
				}
				else
				{
					// 只保留零点记录标志
					MotorStatus[0].Status &= ZERO_RECORD_MASK;	
					MotorStatus[0].Dir = 0;
	
					// 关定时器0
					TR1 = 0;
					ET1 = 0;
					Timer[1].MotorIdx = 0;
					PUL0 = 1;
					break;
				}
			}
		
			// 改变输出电平
			PUL0 = ~PUL0;
	
			// 增减脉冲总数量
			tmpptr = (BYTE idata*)&MotorStatus[0].TotalPluseCnt + LSB;
			if ( DIR0 )
				DWordDec( );
			else
				DWordInc( );

			// 当前脉冲减
			tmpptr = (BYTE idata*)&Timer[1].CurPluseNum + LSB;
			DWordDec( );
			
			// 零位检测
			if ( MotorStatus[0].Status & ZERO_CHECK_MASK )
			{
				// 零位到达
				if ( !LastTimer1ST && ST0 )
				{
					MotorStatus[0].Status |= MOTOR_STOP_CMD_MASK;
					MotorStatus[0].Status |= ZERO_RECORD_MASK;
					MotorStatus[0].TotalPluseCnt = 0;
					break;
				}
				LastTimer1ST = ST0;
			}

			// 脉冲数未完
			if ( Timer[1].CurPluseNum )
				break;
				
			if ( (MotorStatus[0].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
			{
				DIR0 = ~DIR0;
				Timer[1].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[1].CenrerPluse == (WORD)MotorStatus[1].TotalPluseCnt )
					{
						// 只保留零点记录标志
						MotorStatus[1].Status &= ZERO_RECORD_MASK;
						MotorStatus[1].Dir = 0;
						
						// 关定时器0
						TR1 = 0;
						ET1 = 0;
						Timer[1].MotorIdx = 0;
						break;
					}
				}
				else
				{
					// 只保留零点记录标志
					MotorStatus[1].Status &= ZERO_RECORD_MASK;
					MotorStatus[1].Dir = 0;
						
					// 关定时器0
					TR1 = 0;
					ET1 = 0;
					Timer[1].MotorIdx = 0;
					PUL1 = 1;
					break;
				}
			}
		
			// 改变输出电平
			PUL1 = ~PUL1;
	
			// 增减脉冲总数量
			tmpptr = (BYTE idata*)&MotorStatus[1].TotalPluseCnt + LSB;
			if ( DIR1 )
				DWordDec( );
			else
				DWordInc( );

			// 当前脉冲减
			tmpptr = (BYTE idata*)&Timer[1].CurPluseNum + LSB;
			DWordDec( );
			
			// 零位检测
			if ( MotorStatus[1].Status & ZERO_CHECK_MASK )
			{
				// 零位到达
				if ( !LastTimer1ST && ST1 )
				{
					MotorStatus[1].Status |= MOTOR_STOP_CMD_MASK;
					MotorStatus[1].Status |= ZERO_RECORD_MASK;
					MotorStatus[1].TotalPluseCnt = 0;
					break;
				}
				LastTimer1ST = ST1;
			}

			// 脉冲数未完
			if ( Timer[1].CurPluseNum )
				break;
				
			if ( (MotorStatus[1].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
			{
				DIR1 = ~DIR1;
				Timer[1].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[1].CenrerPluse == (WORD)MotorStatus[2].TotalPluseCnt )
					{
						// 只保留零点记录标志
						MotorStatus[2].Status &= ZERO_RECORD_MASK;
						MotorStatus[2].Dir = 0;
						
						// 关定时器0
						TR1 = 0;
						ET1 = 0;
						Timer[1].MotorIdx = 0;
						break;
					}
				}
				else
				{
					// 只保留零点记录标志
					MotorStatus[2].Status &= ZERO_RECORD_MASK;
					MotorStatus[2].Dir = 0;
						
					// 关定时器0
					TR1 = 0;
					ET1 = 0;
					Timer[1].MotorIdx = 0;
					PUL2 = 1;
					break;
				}
			}
		
			// 改变输出电平
			PUL2 = ~PUL2;
	
			// 增减脉冲总数量
			tmpptr = (BYTE idata*)&MotorStatus[2].TotalPluseCnt + LSB;
			if ( DIR2 )
				DWordDec( );
			else
				DWordInc( );

			// 当前脉冲减
			tmpptr = (BYTE idata*)&Timer[1].CurPluseNum + LSB;
			DWordDec( );
			
			// 零位检测
			if ( MotorStatus[2].Status & ZERO_CHECK_MASK )
			{
				// 零位到达
				if ( !LastTimer1ST && ST2 )
				{
					MotorStatus[2].Status |= MOTOR_STOP_CMD_MASK;
					MotorStatus[2].Status |= ZERO_RECORD_MASK;
					MotorStatus[2].TotalPluseCnt = 0;
					break;
				}
				LastTimer1ST = ST2;
			}

#if (SCH_PCB_VERSION == 1)
			// 工作零位检测
			if ( MotorStatus[2].Status & WORK_ZERO_CHECK_MASK )
			{
				// 零位到达
				if ( !LastTimer1WST && WST2 )
				{
					MotorStatus[2].Status |= MOTOR_STOP_CMD_MASK;
					break;
				}
				LastTimer1WST = WST2;
			}
#endif
			// 脉冲数未完
			if ( Timer[1].CurPluseNum )
				break;
				
			if ( (MotorStatus[2].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
			{
				DIR2 = ~DIR2;
				Timer[1].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[1].CenrerPluse == (WORD)MotorStatus[3].TotalPluseCnt )
					{
						// 只保留零点记录标志
						MotorStatus[3].Status &= ZERO_RECORD_MASK;
						MotorStatus[3].Dir = 0;
						
						// 关定时器0
						TR1 = 0;
						ET1 = 0;
						Timer[1].MotorIdx = 0;
						break;
					}
				}
				else
				{
					// 只保留零点记录标志
					MotorStatus[3].Status &= ZERO_RECORD_MASK;
					MotorStatus[3].Dir = 0;
						
					// 关定时器0
					TR1 = 0;
					ET1 = 0;
					Timer[1].MotorIdx = 0;
					PUL3 = 1;
					break;
				}
				break;
			}
		
			// 改变输出电平
			PUL3 = ~PUL3;
	
			// 增减脉冲总数量
			tmpptr = (BYTE idata*)&MotorStatus[3].TotalPluseCnt + LSB;
			if ( DIR3 )
				DWordDec( );
			else
				DWordInc( );

			// 当前脉冲减
			tmpptr = (BYTE idata*)&Timer[1].CurPluseNum + LSB;
			DWordDec( );
			
			// 零位检测
			if ( MotorStatus[3].Status & ZERO_CHECK_MASK )
			{
				// 零位到达
				if ( !LastTimer1ST && ST3 )
				{
					MotorStatus[3].Status |= MOTOR_STOP_CMD_MASK;
					MotorStatus[3].Status |= ZERO_RECORD_MASK;
					MotorStatus[3].TotalPluseCnt = 0;
					break;
				}
				LastTimer1ST = ST3;
			}

			// 脉冲数未完
			if ( Timer[1].CurPluseNum )
				break;
				
			if ( (MotorStatus[3].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
			{
				DIR3 = ~DIR3;
				Timer[1].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[1].CenrerPluse == (WORD)MotorStatus[4].TotalPluseCnt )
					{
						// 只保留零点记录标志
						MotorStatus[4].Status &= ZERO_RECORD_MASK;
						MotorStatus[4].Dir = 0;
						
						// 关定时器0
						TR1 = 0;
						ET1 = 0;
						Timer[1].MotorIdx = 0;
						break;
					}
				}
				else
				{
					// 只保留零点记录标志
					MotorStatus[4].Status &= ZERO_RECORD_MASK;
					MotorStatus[4].Dir = 0;
						
					// 关定时器0
					TR1 = 0;
					ET1 = 0;
					Timer[1].MotorIdx = 0;
					PUL4 = 1;
					break;
				}
				break;
			}
		
			// 改变输出电平
			PUL4 = ~PUL4;
	
			// 增减脉冲总数量
			tmpptr = (BYTE idata*)&MotorStatus[4].TotalPluseCnt + LSB;
			if ( DIR4 )
				DWordDec( );
			else
				DWordInc( );

			// 当前脉冲减
			tmpptr = (BYTE idata*)&Timer[1].CurPluseNum + LSB;
			DWordDec( );
			
			// 零位检测
			if ( MotorStatus[4].Status & ZERO_CHECK_MASK )
			{
				// 零位到达
				if ( !LastTimer1ST && ST4 )
				{
					MotorStatus[4].Status |= MOTOR_STOP_CMD_MASK;
					MotorStatus[4].Status |= ZERO_RECORD_MASK;
					MotorStatus[4].TotalPluseCnt = 0;
					break;
				}
				LastTimer1ST = ST4;
			}

			// 脉冲数未完
			if ( Timer[1].CurPluseNum )
				break;
				
			if ( (MotorStatus[4].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
			{
				DIR4 = ~DIR4;
				Timer[1].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[1].CenrerPluse == (WORD)MotorStatus[5].TotalPluseCnt )
					{
						// 只保留零点记录标志
						MotorStatus[5].Status &= ZERO_RECORD_MASK;
						MotorStatus[5].Dir = 0;
						
						// 关定时器0
						TR1 = 0;
						ET1 = 0;
						Timer[1].MotorIdx = 0;
						break;
					}
				}
				else
				{
					// 只保留零点记录标志
					MotorStatus[5].Status &= ZERO_RECORD_MASK;
					MotorStatus[5].Dir = 0;
						
					// 关定时器0
					TR1 = 0;
					ET1 = 0;
					Timer[1].MotorIdx = 0;
					PUL5 = 1;
					break;
				}
			}
		
			// 改变输出电平
			PUL5 = ~PUL5;
	
			// 增减脉冲总数量
			tmpptr = (BYTE idata*)&MotorStatus[5].TotalPluseCnt + LSB;
			if ( DIR5 )
				DWordDec( );
			else
				DWordInc( );

			// 当前脉冲减
			tmpptr = (BYTE idata*)&Timer[1].CurPluseNum + LSB;
			DWordDec( );
			
			// 零位检测
			if ( MotorStatus[5].Status & ZERO_CHECK_MASK )
			{
				// 零位到达
				if ( !LastTimer1ST && ST5 )
				{
					MotorStatus[5].Status |= MOTOR_STOP_CMD_MASK;
					MotorStatus[5].Status |= ZERO_RECORD_MASK;
					MotorStatus[5].TotalPluseCnt = 0;
					break;
				}
				LastTimer1ST = ST5;
			}

#if (SCH_PCB_VERSION == 1)
			// 工作零位检测
			if ( MotorStatus[5].Status & WORK_ZERO_CHECK_MASK )
			{
				// 零位到达
				if ( !LastTimer1WST && WST5 )
				{
					MotorStatus[5].Status |= MOTOR_STOP_CMD_MASK;
					break;
				}
				LastTimer1WST = WST5;
			}
#endif
			// 脉冲数未完
			if ( Timer[1].CurPluseNum )
				break;
				
			if ( (MotorStatus[5].Dir & DIR_FLAG_MASK) == DIR_FLAG_MASK )
			{
				DIR5 = ~DIR5;
				Timer[1].CurPluseNum = MotorStatus[5].CmdPluseNum;
			}
			else
			{
				// 停止
				MotorStatus[5].Status |= MOTOR_STOP_CMD_MASK;
			}
			break;
	}
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -