微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > stm32F407(CORTEX-M4)之RCC配置与TIM2的PWM

stm32F407(CORTEX-M4)之RCC配置与TIM2的PWM

时间:11-25 来源:互联网 点击:

TIM_ClearFlag(TIM2, TIM_FLAG_Update);
TIM_ITConfig(TIM2, TIM_IT_Update,ENABLE);
TIM_Cmd(TIM2, ENABLE); //使能TIM2定时器
}

void NVIC_Config(void)
{

NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //中断优先级分组为1
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;//嵌套中断通道为TIM2
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //抢占优先级为1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //响应优先级为0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能中断
NVIC_Init(&NVIC_InitStructure);
}

void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while (TimingDelay != 0);
}

void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}

中断服务函数:

void TIM2_IRQHandler(void)
{
if(TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
LED_Flag= ~LED_Flag;


}
}


Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top