假如只运用TIME2大局中止,则不需求void EXTI_Config(void)//外部中止装备。只需void NVIC_Configuration(void)//嵌套中止装备和stm32f10x_it.c库文件中的void TIM2_IRQHandler(void)。详细如下装备。留意此处与外部中止的装备的差异切勿混杂。
疑问?
1.为什么不需求装备RCC_APB2Periph_AFIO
2 检查固件库手册 发现NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn; //挑选外部中止3号线 与
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel; //挑选TIM2中止 是结构体的不同值,怎么回事?
3TIME2是在什么情况下促进发生了TIM2_IRQChannel; 是守时器守时满了?仍是?TIM1有那么多中止方法,那么TIM2的大局中止时什么意思?
void NVIC_Configuration(void)//嵌套中止装备
{
#ifdef VECT_TAB_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM,0x0);
#else
NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0);
#endif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel; //挑选TIM2中止
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;//
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能
NVIC_Init(&NVIC_InitStructure);
}
void TIM2_IRQHandler(void)
{
//USART_SendData(USART2,TIM3->CNT);
/****************此处有误,但程序尽然正常跑,趣了怪了*******
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET)
{
}
******/
/**************改成**********if ( TIM_GetITStatus(TIM2 , TIM_IT_Update) != RESET )
TIM_ClearITPendingBit(TIM2 , TIM_FLAG_Update);//有必要铲除中止标志位不然一向中止
*****************/
Delay(100000);
printf(“TIM3->wangwenwneCNT=%d”,TIM3->CNT);//此函数已被我重定向(fputc())
}
int fputc(int ch,FILE * f)
{
USART_SendData(USART2,(unsigned char)ch);
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET)
{
}
return(ch);
}
void TIMER2_PWM_Init(void)
{
/****装备时刻基**********/
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
TIM_TimeBaseStructure.TIM_Prescaler = 0xFF;//分频
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; //时钟切割
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x03;
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //形式
// TIM_OCInitStructure.TIM_Channel = TIM_Channel_1;
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse=CCR1_Val;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_Low;
TIM_OC1Init(TIM2,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM2,TIM_OCPreload_Disable);
/**********************/
TIM_Cmd(TIM2,ENABLE);
TIM_ITConfig(TIM2,TIM_IT_CC1,ENABLE);
}
榜首种方法:
NVIC_SETPRIMASK(); //封闭总中止
NVIC_RESETPRIMASK(); //敞开总中止
第二种方法:
NVIC_SETFAULTMASK(); //封闭总中止
NV%&&&&&%_RESETFAULTMASK(); //敞开总中止