#define TIM2CH1_CAPTURE_STA TIM2->SR//输入捕获状态
#define TIM2CH1_CAPTURE_VAL TIM2->CCR1//输入捕获CNT的值
void TIM2_IRQHandler()
{
if(TIM_GetFlagStatus(TIM2,TIM_FLAG_Update)!=RESET)//溢出次数
{
flag++;
printf("%d",flag);
delay_ms(200);
}
if((TIM2CH1_CAPTURE_STA&0x03)==0x03)//捕获到了
{
if(Flag_RisingFalling==1) //捕获到上升沿
{
TIM2CH1_CAPTURE_STA&=0Xfd; //标志位置0
printf("A=%d\r\n",TIM2CH1_CAPTURE_VAL);
delay_ms(10);
TIM2CH1_CAPTURE_VAL;
TIM_SetCounter(TIM2,0);//把计数器和CCR1的值都置0
Flag_RisingFalling=0;//上升沿 1,下降沿 0
TIM_OC1PolarityConfig(TIM2,TIM_ICPolarity_Falling); //CC1P=0 设置为下降沿捕获
}
else //捕获到下降沿
{
TIM2CH1_CAPTURE_STA&=0Xfd;
TIM2CH1_CAPTURE_VAL;
printf("B=%d\n",TIM2CH1_CAPTURE_VAL);
delay_ms(10);
Flag_RisingFalling=1;
TIM_OC1PolarityConfig(TIM2,TIM_ICPolarity_Rising); //CC1P=0 设置为上升沿捕获
}
}
TIM_ClearITPendingBit(TIM2, TIM_IT_CC1|TIM_IT_Update); //清除中断标志位
}
请问为什么我把程序下载后,串口自动打印数据?
|