void dipan()//电机控制部分程序 { u32 pwm0=0,pwm1=0,pwm2=0,pwm3=0,duoji0,duoji1; LED_Init(); TIM4_CH2_PWM_Init(100-1,84-1); //84M/84=1MHz的计数频率,重装载值20000,所以PWM频率为1M/20000=50Hz. if ((Channel_0>1000&&Channel_0<1060)) { delay_ms(2); } if ((Channel_1>1000&&Channel_1<1060)) { delay_ms(2); } if ((Channel_0>1060&&Channel_0<1684&&Channel_1>1000&&Channel_1<1060)) { GPIO_SetBits(GPIOG,GPIO_Pin_8); //GPIO_SetBits//GPIO_ResetBits GPIO_ResetBits(GPIOC,GPIO_Pin_9); GPIO_SetBits(GPIOC,GPIO_Pin_11); GPIO_ResetBits(GPIOA,GPIO_Pin_13); pwm2=(int)(-15*Channel_0/66+233+15*1024/66); TIM_SetCompare2(TIM4,pwm2); TIM_SetCompare1(TIM4,pwm2); } if((Channel_0>364&&Channel_0<1000&&Channel_1>1000&&Channel_1<1060))//GPIO_SetBits//GPIO_ResetBits { GPIO_SetBits(GPIOC,GPIO_Pin_9); GPIO_ResetBits(GPIOG,GPIO_Pin_8); GPIO_SetBits(GPIOA,GPIO_Pin_13); GPIO_ResetBits(GPIOC,GPIO_Pin_11); pwm3=(int)(15*Channel_0/66+233-15*1024/66); TIM_SetCompare2(TIM4,pwm3); TIM_SetCompare1(TIM4,pwm3); } if((Channel_1>1060&&Channel_1<1684&&Channel_0>1000&&Channel_0<1060))//GPIO_SetBits//GPIO_ResetBits { GPIO_ResetBits(GPIOG,GPIO_Pin_8); GPIO_SetBits(GPIOC,GPIO_Pin_9); GPIO_ResetBits(GPIOA,GPIO_Pin_13); GPIO_SetBits(GPIOC,GPIO_Pin_11); pwm0=(int)(-15*Channel_1/66+233+15*1024/66); pwm0=(int)(-180*Channel_1/66+600+1684*180/66); TIM_SetCompare2(TIM4,pwm0); TIM_SetCompare1(TIM4,pwm0); } if ((Channel_1>364&&Channel_1<1000&&Channel_0>1000&&Channel_0<1060)) { GPIO_ResetBits(GPIOC,GPIO_Pin_9); GPIO_SetBits(GPIOG,GPIO_Pin_8); GPIO_ResetBits(GPIOC,GPIO_Pin_11); GPIO_SetBits(GPIOA,GPIO_Pin_13); pwm1=(int)(15*Channel_1/66+233-15*1024/66); TIM_SetCompare2(TIM4,pwm1); TIM_SetCompare1(TIM4,pwm1); } if ((Channel_3>1024&&Channel_3<=1630)) { duoji0=Channel_3*50/33+559300/33; TIM_SetCompare1(TIM13,duoji0); } if ((Channel_2>1024&&Channel_2<=1684)) { duoji1=Channel_2*50/33+559300/33; TIM_SetCompare1(TIM14,duoji1); } //机械手电机控制部分 if(Channel_s2==1) //舵机上升 { delay_ms(2); TIM_SetCompare1(TIM14,19450); } if(Channel_s1==2)//舵机合死 { delay_ms(2); TIM_SetCompare1(TIM13,19155); } if(Channel_s2==2)//舵机下降 { delay_ms(2); TIM_SetCompare1(TIM14,18325); } if(Channel_s1==1)//舵机打开 { delay_ms(2); TIM_SetCompare1(TIM13,18500); } }