#include "stm32f10x.h" // Device header
void TIM1_PWM_Enable(void)
{
TIM1->CCER |= 0x0005; // 使能输出
}
void TIM1_PWM_Disable(void)
{
TIM1->CCER &= ~0x0005;//必须得让互补的两位复位,使用0x0001的话在复位后第一次按下时还会出现一次高电平
}
int main(void)
{
// 结构体声明
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;//时基结构体,
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRStructure;
// 时钟使能
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE); //TIM1时钟使能
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOA, ENABLE); //使能PORTE时钟
// IO配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //速度100MHz
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_Init(GPIOA,&GPIO_InitStructure); //初始化PA8
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_
使用STM32F103C8T6的TIM1定时器PWM互补输出(带死区),按下停止后保持低电平(标准库)
于 2024-01-18 12:55:48 首次发布