新手入门
- 积分
- 9
- 金钱
- 9
- 注册时间
- 2021-5-16
- 在线时间
- 1 小时
|
1金钱
一下为代码
void TIM14_PWM_Init(u32 arr,u32 psc)//初始化函数
{
GPIO_InitTypeDef GPIO_struct; TIM_TimeBaseInitTypeDef TIM_initstruct;
TIM_OCInitTypeDef TIM_ocinitstruct;
GPIO_struct.GPIO_Mode=GPIO_Mode_AF;
GPIO_struct.GPIO_OType=GPIO_OType_PP;
GPIO_struct.GPIO_Pin=GPIO_Pin_10|GPIO_Pin_9;
GPIO_struct.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_struct.GPIO_Speed=GPIO_Speed_50MHz;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
GPIO_PinAFConfig(GPIOF,GPIO_PinSource10,GPIO_AF_TIM14);
GPIO_PinAFConfig(GPIOF,GPIO_PinSource9,GPIO_AF_TIM14);
GPIO_Init(GPIOF,&GPIO_struct);
TIM_initstruct.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_initstruct.TIM_CounterMode=TIM_CounterMode_Up;
TIM_initstruct.TIM_Period=arr;
TIM_initstruct.TIM_Prescaler=psc;
TIM_TimeBaseInit(TIM14,&TIM_initstruct);
TIM_ocinitstruct.TIM_OCMode=TIM_OCMode_PWM1;
TIM_ocinitstruct.TIM_OutputState=TIM_OutputState_Enable;
TIM_ocinitstruct.TIM_OCPolarity=TIM_OCPolarity_Low;
TIM_OC1Init(TIM14,&TIM_ocinitstruct);
TIM_OC1PreloadConfig(TIM14,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM14,ENABLE);
TIM_Cmd(TIM14,ENABLE);
}
其他代码与历程相同,为什么呼吸灯只有PF9在变化,PF10常亮
|
|