这个问题比较简单,献丑啦。
不过对新人很有帮助,哇哈哈,看代码:
/* Time base configuration,clk=cpu=16M,时钟125K,计数周期为500Hz=2ms */ TIM1_TimeBaseInit(127, TIM1_COUNTERMODE_UP,LED_PWM_INIT,0); /* PWM1 Mode configuration: Channel1 */ TIM1_OC3Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_DISABLE, LED_PWM_INIT>>1, TIM1_OCPOLARITY_LOW,TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_RESET,TIM1_OCNIDLESTATE_RESET); TIM1_OC3PreloadConfig(ENABLE); TIM1_CCxCmd(TIM1_CHANNEL_3,ENABLE); TIM1_CtrlPWMOutputs(ENABLE); // 若不使能,TIM1是不会产生PWM输出的 //TIM1_ARRPreloadConfig(ENABLE); /* enable counter */ TIM1_Cmd(ENABLE);
更改占空比:
TIM1_SetCompare3(pe);
有帮助别忘了打赏: