2019-07-20 22:32发布
Zx1291 发表于 2016-2-2 12:37 噢,我想起来了,在学校实验室电脑上传的,我们实验室的电脑都加密了,没事,你哪里不太明白的可以问我, ...
最多设置5个标签!
[mw_shl_code=c,true]void TIM3_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); ///ê1ÄüTIM3ê±Öó
TIM_TimeBaseInitStructure.TIM_Period = arr; //100ms
TIM_TimeBaseInitStructure.TIM_Prescaler= psc; //¶¨ê±Æ÷·ÖÆμ
//¶¨ê±Æ÷ê±Öó84M£¬·ÖÆμÏμêy8400£¬ËùòÔ84M/8400=10KhzμļÆêyÆμÂ꣬¼Æêy5000′ÎÎa500ms
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //ÏòéϼÆêyÄ£ê½
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);//3õê¼»ˉTIM3
TIM_SelectOutputTrigger(TIM3,TIM_TRGOSource_Update);
TIM_OCInitStructure.TIM_OCMode =TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;//TIM_OutputState_Disable;
TIM_OCInitStructure.TIM_Pulse = 5000;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;//???PWM1??Low,PWM2??High
TIM_OC2Init(TIM2, & TIM_OCInitStructure);
TIM_InternalClockConfig(TIM3);
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_UpdateDisableConfig(TIM3, DISABLE);
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE); //ÔêDí¶¨ê±Æ÷3¸üDÂÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn; //¶¨ê±Æ÷3ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x01; //ÇàÕ¼óÅÏ輶1
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x03; //×óóÅÏ輶3
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_Cmd(TIM3,ENABLE); //ê1Äü¶¨ê±Æ÷3
}
//¶¨ê±Æ÷3ÖD¶Ï·tÎñoˉêy
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update)==SET) //òç3öÖD¶Ï
{
LED1=!LED1;//DS1·-×a
}
TIM_ClearITPendingBit(TIM3,TIM_IT_Update); //Çå3yÖD¶Ï±ê־λ
}[/mw_shl_code]
这样配置TIM怎么不对呢
一周热门 更多>