中级会员
- 积分
- 277
- 金钱
- 277
- 注册时间
- 2017-3-17
- 在线时间
- 120 小时
|
1金钱
按手册上敲的,但定时器5还是一直在运行任务函数
[mw_shl_code=c,true]void interrupt_task(void *pvParameters)
{
static u32 total_num=0;
while(1)
{
total_num += 1;
if(total_num == 5)
{
printf("关闭中断.........\r\n");
portDISABLE_INTERRUPTS(); //关闭中断
delay_ms(5000); //延时5s
printf("打开中断.........\r\n"); //打开中断
portENABLE_INTERRUPTS(); //打开中断
}
LED0 =~ LED0;
vTaskDelay(1000);
}
}[/mw_shl_code]
定时器的定义
[mw_shl_code=c,true]void TIM3_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); ///使能TIM2时钟
TIM_TimeBaseInitStructure.TIM_Period = arr; //自动重装载值
TIM_TimeBaseInitStructure.TIM_Prescaler=psc; //定时器分频
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);//初始化TIM3
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE); //允许定时器3更新中断
TIM_Cmd(TIM3,ENABLE); //使能定时器3
NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn; //定时器3中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x04; //抢占优先级4
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x00; //子优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}[/mw_shl_code]
[mw_shl_code=c,true]void TIM5_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE); ///使能TIM5时钟
TIM_TimeBaseInitStructure.TIM_Period = arr; //自动重装载值
TIM_TimeBaseInitStructure.TIM_Prescaler=psc; //定时器分频
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM5,&TIM_TimeBaseInitStructure);//初始化TIM5
TIM_ITConfig(TIM5,TIM_IT_Update,ENABLE); //允许定时器5更新中断
TIM_Cmd(TIM5,ENABLE); //使能定时器5
NVIC_InitStructure.NVIC_IRQChannel=TIM5_IRQn; //定时器5中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x05; //抢占优先级5
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x00; //子优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}[/mw_shl_code]
|
-
|