u8 i=0;
for(i=0;i { Led_On; DelayMs(100*n); Led_Off; DelayMs(100*n); } } /***************************************************************************************** 函数:void SetPWMduty(u8 PWMChanel,u16 pulse) 描述:设置pwm波占空比 参数: 返回: *****************************************************************************************/ void SetPWMduty(u8 PWMChanel,u16 pulse) { switch(PWMChanel) { case 1 : TIM1->CCR1=pulse; break; case 2 : TIM1->CCR2=pulse; break; case 3 : TIM1->CCR3=pulse; break; default : break; } } /******************************************************************************* 函数:PWM_T_Output 描述:设置相应的PWM梯形波输出 参数:pName上桥臂名称,nName下桥臂名称 返回:无 ********************************************************************************/ void PWM_T_Output(u8 pName , u8 nName , u8 mRate) { switch(pName) { case 1: GPIO_SetBits(GPIOB, GPIO_Pin_15 | GPIO_Pin_14 ); GPIO_ResetBits(GPIOB , GPIO_Pin_13); break; case 2: GPIO_SetBits(GPIOB, GPIO_Pin_13 | GPIO_Pin_15 ); GPIO_ResetBits(GPIOB , GPIO_Pin_14); break; case 3: GPIO_SetBits(GPIOB, GPIO_Pin_13 | GPIO_Pin_14 ); GPIO_ResetBits(GPIOB , GPIO_Pin_15); break; default: GPIO_SetBits(GPIOB, GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); } switch(nName) { case 1: TIM_SetCompare2(TIM1,0); TIM_SetCompare3(TIM1,0); TIM_SetCompare1(TIM1,(u16)(PWM_PERIOD_T * mRate / 100)); break; case 2: TIM_SetCompare3(TIM1,0); TIM_SetCompare1(TIM1,0); TIM_SetCompare2(TIM1,(u16)(PWM_PERIOD_T * mRate / 100)); break; case 3: TIM_SetCompare2(TIM1,0); TIM_SetCompare1(TIM1,0); TIM_SetCompare3(TIM1,(u16)(PWM_PERIOD_T * mRate / 100)); break; default: TIM_SetCompare1(TIM1,0); TIM_SetCompare2(TIM1,0); TIM_SetCompare3(TIM1,0);