新手入门
- 积分
- 17
- 金钱
- 17
- 注册时间
- 2021-7-13
- 在线时间
- 4 小时
|

楼主 |
发表于 2021-7-16 00:56:47
|
显示全部楼层
- #include "pwm.h"
- #include "led.h"
- #include "usart.h"
- void PWM_Init(u32 arr,u32 psc)
- {
- GPIO_InitTypeDef GPIO_InitStructer;
- TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructer;
- TIM_OCInitTypeDef TIM_OCInitStructer;
-
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14,ENABLE);
- RCC_APB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
-
- GPIO_PinAFConfig(GPIOF,GPIO_PinSource9,GPIO_AF_TIM14);
-
- GPIO_InitStructer.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructer.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructer.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStructer.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_InitStructer.GPIO_Speed = GPIO_High_Speed;
-
- GPIO_Init(GPIOF,&GPIO_InitStructer);
-
- TIM_TimeBaseInitStructer.TIM_ClockDivision = TIM_CKD_DIV1;
- TIM_TimeBaseInitStructer.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInitStructer.TIM_Period = arr;
- TIM_TimeBaseInitStructer.TIM_Prescaler = psc;
- TIM_TimeBaseInit(TIM14,&TIM_TimeBaseInitStructer);
-
- TIM_OCInitStructer.TIM_OutputState= TIM_OutputState_Enable;
- TIM_OCInitStructer.TIM_OCMode = TIM_OCMode_PWM1;
- TIM_OCInitStructer.TIM_OCPolarity = TIM_OCPolarity_Low;
- TIM_OC1Init(TIM14,&TIM_OCInitStructer);
- TIM_OC1PreloadConfig(TIM14, TIM_OCPreload_Enable);
- TIM_ARRPreloadConfig(TIM14,ENABLE);
- TIM_Cmd(TIM14, ENABLE);
-
- }
复制代码
//我的代码,上面好像看不见 |
|