TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_DeInit(TIM1);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
TIM_TimeBaseStructure.TIM_Prescaler = 8 - 1; //8·ÖƵ(Ó벶»ñ·ÖƵÏàͬ)
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //ÏòÉϼÆÊýģʽ
TIM_TimeBaseStructure.TIM_Period = 0xFFFFFFFF; //¶¨Ê±ÖÜÆÚ(×Ô¶¯´Ó×°ÔؼĴæÆ÷ARRµÄÖµ)
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //ʱÖÓ·ÖƵÒò×Ó
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM1,TIM_IT_Update|TIM_IT_CC2,ENABLE);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2; //ͨµÀ2
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //²¶»ñ¼«ÐÔ
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //²¶»ñÑ¡Ôñ
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV8; //²¶»ñ·ÖƵ
TIM_ICInitStructure.TIM_ICFilter = 0x0; //²¶»ñÂ˲¨
TIM_ICInit(TIM1, &TIM_ICInitStructure);
TIM_Cmd(TIM1, ENABLE);
void TIMER_IC_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //LEDÒý½Å
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //¸´ÓÃģʽ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //¸ßËÙÊä³ö
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //ÍÆÍêÊä³ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //ÎÞÉÏÏÂÀ­(¸¡¿Õ)
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_2); //¸´ÓÃÅäÖÃ
}
void TIM1_CC_IRQHandler(void)
{
if(TIM_GetITStatus(TIM1, TIM_IT_CC2) != RESET)
{
TIM_ClearFlag(TIM1, TIM_IT_CC2);
}
}
这是我的程序,现在的问题是这个程序如果改成通道1可用,可是改成通道2就不进中断了。看寄存器CNT仿真一直在变。困扰很久,求助大家。麻烦有大家知道一下
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>