我用的stm8单片机,解了个同步头,接了个蜂鸣器,但每次按一下遥控器蜂鸣器只叫一声,按道理按着遥控器应该发很多同步头。我用的是捕获模式。
#pragma vector = 0x0e
__interrupt void TIM1_CAPTURE_ISR( void )
{
TIM1_SR1 &= ~( 0x10 ); //清除通道1捕获中断标志
if(( ( TIM1_CCER2 >> 5 ) && 0x01 ) )//如果上升沿触发
{
HL1_Numble = ( TIM1_CCR4H << 8 );
HL1_Numble |= TIM1_CCR4L; //读高电平时间
TIM1_CCER2 &= ~( 1 << 5 );//改为下降沿触发
}
else//如果上升沿触发
{
HL2_Numble = ( TIM1_CCR4H << 8 );
HL2_Numble |= TIM1_CCR4L;
HL2_Numble -= HL1_Numble; //读低电平时间
TIM1_CNTRH = 0x00;
TIM1_CNTRL = 0x00;//计数器清零
TIM1_CCER2 |= 1 << 5 ;//改为上升沿触发
}
if((( HL1_Numble < H150um_Numble ) && ( HL1_Numble > L150um_Numble )) &&\
(( HL2_Numble < H5ms_Numble ) && ( HL2_Numble > L5ms_Numble )))
{
FENG_ON( 1 );
}
} |