高级会员

- 积分
- 609
- 金钱
- 609
- 注册时间
- 2016-8-31
- 在线时间
- 82 小时
|
void TIM1_EncoderConfig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
/*ê1Äü¶¨ê±Æ÷ê±Öó*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 | RCC_APB2Periph_GPIOA, ENABLE);
/*GPIO configuration*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
TIM_TimeBaseInitStruct.TIM_Period = 65535;
TIM_TimeBaseInitStruct.TIM_Prescaler = 0; //2»·ÖÆμ
TIM_TimeBaseInitStruct.TIM_ClockDivision = 0;
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseInitStruct);
/*ê1Äü×Ô¶ˉÖØÔØÔ¤×°ÔØ*/
TIM_ARRPreloadConfig(TIM1, ENABLE);
TIM_EncoderInterfaceConfig(TIM1, TIM_EncoderMode_TI12, TIM_ICPolarity_Falling, TIM_ICPolarity_Falling);
TIM_GenerateEvent(TIM1, TIM_EventSource_Update);
/*Çå3y¸üD±êÖ¾*/
TIM_ClearFlag(TIM1, TIM_FLAG_Update);
/*¶¨ê±Æ÷¿a1Ø*/
TIM_Cmd(TIM1,ENABLE);
}
|
|