博士
最后登录1970-1-1
在线时间 小时
注册时间2017-2-5
|
发表于 2017-4-9 18:28:23
|
显示全部楼层
#include "bsp_tim.h"
void BSP_TIM_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = BSP_TIM_IRQ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void BSP_TIM_MODE_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
BSP_TIM_APBxClock_FUN(BSP_TIM_CLK,ENABLE);
TIM_TimeBaseStructure.TIM_Period = BSP_TIM_Period;
TIM_TimeBaseStructure.TIM_Prescaler = BSP_TIM_Prescaler;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(BSP_TIM,&TIM_TimeBaseStructure);
TIM_ClearFlag(BSP_TIM, TIM_FLAG_Update);
TIM_ITConfig(BSP_TIM, TIM_IT_Update, ENABLE);
TIM_Cmd(BSP_TIM, ENABLE);
//BSP_TIM_APBxClock_FUN(BSP_TIM_CLK, DISABLE);
}
定时器
void BSP_TIM_IRQHandler(void)
{
if( TIM_GetITStatus(BSP_TIM,TIM_IT_Update) != RESET )
{
time++;
TIM_ClearITPendingBit(BSP_TIM,TIM_FLAG_Update);
}
}
中断
只需要在主函数中设定time的值就可以实现延时效果
火哥的例程资料中有 你可以看看 |
|