初级会员
- 积分
- 113
- 金钱
- 113
- 注册时间
- 2016-12-19
- 在线时间
- 30 小时
|
楼主 |
发表于 2017-3-7 12:45:11
|
显示全部楼层
void Timer7_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7,ENABLE); ///ê1ÄüTIM3ê±Öó
TIM_TimeBaseInitStructure.TIM_Period = arr; //×Ô¶ˉÖØ×°ÔØÖμ
TIM_TimeBaseInitStructure.TIM_Prescaler=psc; //¶¨ê±Æ÷·ÖÆμ
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //ÏòéϼÆêyÄ£ê½
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM7,&TIM_TimeBaseInitStructure);//3õê¼»ˉTIM3
TIM_ITConfig(TIM7,TIM_IT_Update,ENABLE); //ÔêDí¶¨ê±Æ÷3¸üDÂÖD¶Ï
TIM_Cmd(TIM7,ENABLE); //ê1Äü¶¨ê±Æ÷4
NVIC_InitStructure.NVIC_IRQChannel=TIM7_IRQn; //¶¨ê±Æ÷4ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x02; //ÇàÕ¼óÅÏ輶1
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x03; //×óóÅÏ輶3
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM7_IRQHandler(void)
{
OSIntEnter(); //½øèëÖD¶Ï
if (TIM_GetITStatus(TIM7, TIM_IT_Update)==SET)//êǸüDÂÖD¶Ï
{
OSSemPost(MotorTick);
}
TIM_ClearITPendingBit(TIM7, TIM_IT_Update ); //Çå3yTIM7¸üDÂÖD¶Ï±êÖ¾
OSIntExit();//′¥·¢èÎÎñÇD»»èíÖD¶Ï
}
这是代码 |
|