新手上路
- 积分
- 30
- 金钱
- 30
- 注册时间
- 2018-7-11
- 在线时间
- 4 小时
|
楼主 |
发表于 2018-7-13 09:13:08
|
显示全部楼层
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
TIM2_Int_Init(999,839); //100hz
while(1);
}
void TIM2_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE); ///ê1ÄüTIM3ê±Öó
TIM_TimeBaseInitStructure.TIM_Prescaler=psc; //¶¨ê±Æ÷·ÖÆμ
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //ÏòéϼÆêyÄ£ê½
TIM_TimeBaseInitStructure.TIM_Period=(u32)arr; //×Ô¶ˉÖØ×°ÔØÖμ
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_DeInit(TIM2);
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitStructure);
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE); //ÔêDí¶¨ê±Æ÷3¸üDÂÖD¶Ï
TIM_Cmd(TIM2,ENABLE); //ê1Äü¶¨ê±Æ÷3
NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn; //¶¨ê±Æ÷3ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x01; //ÇàÕ¼óÅÏ輶1
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x00; //×óóÅÏ輶3
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//¶¨ê±Æ÷3ÖD¶Ï·tÎñoˉêy
void TIM2_IRQHandler(void)
{
if(TIM_GetITStatus(TIM2,TIM_IT_Update)==SET) //òç3öÖD¶Ï
{
// lwip_localtime +=10; //¼ó10
}
TIM_ClearITPendingBit(TIM2,TIM_IT_Update); //Çå3yÖD¶Ï±ê־λ
}
现在啥也不做了,纯粹测试,关键是以前写的程序跟定时器有关的全都不能用了,怀疑是硬件问题,今天上示波器看看时钟。 |
|