在设置TIM8定时中断的时候
TIM8_CC_IRQn出错
可是在中是有定义的(更新了这个库,老师给的好像没有)
为什么会报错啊?还是不应该这样写TIM8的中断??
代码如下
#include "stm32f10x.h" #include "misc.h" void RCC_Configuration(void); void NVIC_Configuration(void); void GPIO_Configuration(void); void TIM2_Configuration(void); void TIM3_Configuration(void); void TIM8_Configuration(void); void RCC_Configuration(void) { SystemInit();//24兆 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);//TIM3外设时钟打开,TIM3是挂在APB1上的,一 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);//TIM2外设时钟打开,TIM2是挂在APB1上的,一 RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);//TIM8外设时钟打开,TIM8是挂在APB2上的,一 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);//GPIOC外设时钟打开 } void NVIC_Configuration(void)//设置中断,二 { NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//抢占优先级 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;//响应式优先级 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//抢占优先级 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;//响应式优先级 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel =TIM8_CC_IRQn ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//抢占优先级 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;//响应式优先级 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void GPIO_Configuration(void)//三,LED配置 { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6;//使用到PC1.2.3 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); } void TIM2_Configuration(void)//四,定时器配置 { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructure.TIM_Period = 4999;//计4999个数就产生一次更新事件,4999+1=5000,5000*0.1ms=0.5s TIM_TimeBaseStructure.TIM_Prescaler = 2399;//预分频系数为2399,则计数器的时钟为24MHZ/2399+1=10kHZ,1/10000=0,0001.即0.1ms //预分频数取值范围为0~65535 TIM_TimeBaseStructure.TIM_ClockDivision = 0;// TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//向上计数模式,从0开始向上 TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);//将配置应用到TIM3中 } void TIM3_Configuration(void)//四,定时器配置 { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructure.TIM_Period = 9999;//计9999个数就产生一次更新事件,9999+1=10000,10000*0.1ms=1s TIM_TimeBaseStructure.TIM_Prescaler = 2399;//预分频系数为2399,则计数器的时钟为24MHZ/2399+1=10kHZ,1/10000=0,0001.即0.1ms TIM_TimeBaseStructure.TIM_ClockDivision = 0;// TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//向上计数模式,从0开始向上 TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);//将配置应用到TIM3中 } void TIM1_Configuration(void)//四,定时器配置 { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructure.TIM_Period = 9999;//计9999个数就产生一次更新事件,9999+1=10000,10000*0.1ms=1s TIM_TimeBaseStructure.TIM_Prescaler = 2399;//预分频系数为2399,则计数器的时钟为24MHZ/2399+1=10kHZ,1/10000=0,0001.即0.1ms TIM_TimeBaseStructure.TIM_ClockDivision = 0;// TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//向上计数模式,从0开始向上 TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);//将配置应用到TIM8中 } int main(void) { RCC_Configuration(); NVIC_Configuration(); GPIO_Configuration(); TIM2_Configuration(); TIM3_Configuration(); TIM8_Configuration(); TIM_ClearFlag(TIM8, TIM_FLAG_Update); TIM_ClearFlag(TIM2, TIM_FLAG_Update); TIM_ClearFlag(TIM3, TIM_FLAG_Update); TIM_ARRPreloadConfig(TIM8, DISABLE); TIM_ARRPreloadConfig(TIM2, DISABLE); TIM_ARRPreloadConfig(TIM3, DISABLE); TIM_ITConfig(TIM8, TIM_IT_Update, ENABLE); TIM_Cmd(TIM1, ENABLE);//开启定时器TIM1 TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); TIM_Cmd(TIM2, ENABLE);//开启定时器TIM2 TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE); TIM_Cmd(TIM3, ENABLE);//开启定时器TIM3 while (1) { } } #include "stm32f10x_it.h" void TIM8_IRQHandler(void) { if (TIM_GetITStatus(TIM8, TIM_IT_Update) != RESET) //检测是否发生溢出更新事件 { TIM_ClearITPendingBit(TIM8, TIM_IT_Update); GPIO_WriteBit(GPIOC, GPIO_Pin_0|GPIO_Pin_4, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_0|GPIO_Pin_4)));//取反库函数 } } void TIM2_IRQHandler(void) { if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) //检测是否发生溢出更新事件 { TIM_ClearITPendingBit(TIM2, TIM_IT_Update); GPIO_WriteBit(GPIOC, GPIO_Pin_2|GPIO_Pin_6, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_2|GPIO_Pin_6)));//取反库函数 } } void TIM3_IRQHandler(void) { if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //检测是否发生溢出更新事件 { TIM_ClearITPendingBit(TIM3, TIM_IT_Update); GPIO_WriteBit(GPIOC, GPIO_Pin_1|GPIO_Pin_5, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_1|GPIO_Pin_5)));//取反库函数 } }