這是中斷初始化
void TIM_INIT(void)
{
??? TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure={0};
??? NVIC_InitTypeDef NVIC_InitStructure;
??? RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
??? TIM_TimeBaseInitStructure.TIM_Period = 1000; //定時器自動重裝載計數(shù)周期值,當(dāng)計數(shù)寄存器的值遞增到等于該值時,將相關(guān)事件標志位置位,范圍0~65535。
??? TIM_TimeBaseInitStructure.TIM_Prescaler = 48000-1;? //計數(shù)器預(yù)分頻設(shè)置0-65535
??? TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; //時鐘分頻。有不分頻、二分頻、四分頻?;径〞r器沒有這個功能
??? TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
??? TIM_TimeBaseInit( TIM1, &TIM_TimeBaseInitStructure);
??? TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE ); //使能TIM1中斷,允許更新中斷
??? NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;? //TIM1溢出中斷
??? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //設(shè)置搶占優(yōu)先級0
??? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;??????? //設(shè)置響應(yīng)優(yōu)先級3
??? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;?????????? //使能通道1中斷
??? NVIC_Init(&NVIC_InitStructure); //初始化NVIC
??? TIM_Cmd(TIM1, ENABLE); //TIM1使能
}
void TIM1_UP_IRQHandler(void)
{
??? if(TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET) //檢查TIM1中斷是否發(fā)生。
????? {
??????? TIM_ClearITPendingBit(TIM1,TIM_IT_Update);??? //清除TIM1的中斷掛起位。
??????? IOTtimeCount++;
????? }
}