各位好:
想做个定时器。怎么测试也不对。贴出程序求助大家。我使用的是PA0推腿。程序如下:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
RCC_APB2Periph_GPIOG | RCC_APB2Periph_GPIOE |
RCC_APB2Periph_GPIOF, ENABLE);//管脚时钟使能
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);//时钟使能
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//初始化IO
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_Init(&NVIC_InitStructure);//中断使能
TIM_TimeBaseStructure.TIM_Period = 0x0000; //设置自动装载寄存器
TIM_TimeBaseStructure.TIM_Prescaler = 0; //分频计数
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //选择向上计数
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM2, ENABLE); //是能定时器
程序在执行TIM_Cmd(TIM2, ENABLE); 再也执行不下去了,一直进中断。但是中断我清楚标志了
void TIM2_IRQHandler(void)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
}。
特此求助,或者谁有验证过的定时器程序发一个谢谢 |