各位大佬,小弟刚学单片机,下面是f407的关于脉冲计数的程序,可是怎么计数一直为0了,不知道到底是哪错了。
void TIM1_Counter_Init()
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructuer;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
GPIO_InitStructuer.GPIO_Pin=GPIO_Pin_12;
GPIO_InitStructuer.GPIO_Mode=GPIO_Mode_IN;
GPIO_InitStructuer.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_InitStructuer.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_InitStructuer.GPIO_OType=GPIO_OType_OD;
GPIO_Init(GPIOA,&GPIO_InitStructuer);
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_TIM10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_TimeBaseInitStructure.TIM_Period = 65535;
TIM_TimeBaseInitStructure.TIM_Prescaler=0;
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_ClockDivision=0;
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseInitStructure);
TIM_ETRClockMode2Config(TIM1, TIM_ExtTRGPSC_OFF,TIM_ExtTRGPolarity_NonInverted, 5);
TIM_ClearITPendingBit(TIM1,TIM_IT_Update);
TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
TIM_SetCounter(TIM1,0);
TIM_Cmd(TIM1,ENABLE);
}
void TIM1_UP_TIM10_IRQHandler(void)
{
if(TIM_GetITStatus(TIM1,TIM_IT_Update)==SET)
{
TIM_ClearITPendingBit(TIM1,TIM_IT_Update);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
嗯嗯
一周热门 更多>