STM32F103系列单片机PWM
只需调用函数"set_pwm_high()"以及输入参数(PA11引脚)。
“pwm.h”
#ifndef PWM_H
#define PWM_H
#define LED1_ON() do{GPIO_SetBits (GPIOA, GPIO_Pin_11);}while(0);//PA11打开
#define LED1_OFF() do{GPIO_ResetBits (GPIOA, GPIO_Pin_11);}while(0);//PA11关闭
#include “stm32f10x.h”
#include “stm32f10x_tim.h”
#include “stm32f10x_gpio.h”
#include “stm32f10x_rcc.h”
void led_gpio_init(void);
void systick_init(void);
void tim2_nvic_config(void);
void tim2_config(void);
void set_pwm_high(u8 high_tm);
extern u8 pwm_high;
extern u8 pwm_fq;
#endif
“pwm.c”
#include “pwm.h”
u8 led0_state;
u8 pwm_high;
u8 pwm_fq;
void led_gpio_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/使能GPIOB的rcc时钟/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
/*配置GPIO引脚*/
GPIO_InitStr