STM32F1所有PWM输出配置
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "usart.h"
- #include "timer.h"
-
-
- int main(void)
- {
- delay_init(); //延时函数初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
- LED_Init(); //LED端口初始化
- TIM3_PWM_Init(899,0); //不分频。PWM频率=72000000/900=80Khz
- while(1)
- {
-
- TIM_SetCompare3(TIM2,100);
- TIM_SetCompare4(TIM2,100);
-
- TIM_SetCompare1(TIM3,100);
- TIM_SetCompare2(TIM3,100);
-
- TIM_SetCompare1(TIM1,100);
- TIM_SetCompare2(TIM1,100);
- TIM_SetCompare3(TIM1,100);
- TIM_SetCompare4(TIM1,100);
-
- TIM_SetCompare3(TIM3,100);
- TIM_SetCompare4(TIM3,100);
-
- TIM_SetCompare1(TIM4,100);
- TIM_SetCompare2(TIM4,100);
- TIM_SetCompare3(TIM4,100);
- TIM_SetCompare4(TIM4,100);
-
- delay_ms(5000);
-
- TIM_SetCompare3(TIM2,600);
- TIM_SetCompare4(TIM2,600);
- TIM_SetCompare1(TIM3,600);
- TIM_SetCompare2(TIM3,600);
-
- TIM_SetCompare1(TIM1,600);
- TIM_SetCompare2(TIM1,600);
- TIM_SetCompare3(TIM1,600);
- TIM_SetCompare4(TIM1,600);
-
- TIM_SetCompare3(TIM3,600);
- TIM_SetCompare4(TIM3,600);
-
- TIM_SetCompare1(TIM4,600);
- TIM_SetCompare2(TIM4,600);
- TIM_SetCompare3(TIM4,600);
- TIM_SetCompare4(TIM4,600);
-
- delay_ms(5000);
- }
- }
复制代码
Keil代码工程:
电调_PWM_USART.7z
(185.09 KB, 下载次数: 49)
|