定时器配置如下
TIM5_CAP_Init(3,0XFFFF);
void TIM5_CAP_Init(unsigned char psc,unsigned int arr)
{
TIM5_PSCR = 0X0E;
TIM5_CCER1 &= 0XEE; // 禁止输入捕获 1,2
TIM5_CCER2 &= 0XFE; // 禁止输入捕获 3
TIM5_CCMR1 |= 0x01; // ch1到ti1fp1
TIM5_CCER1 |= 0x02; // ch1 下降沿触发
TIM5_CCMR3 |= 0x01; // ch3选择 ti1fp2上
TIM5_CCER2 |= 0x02; // ch3 下降沿触发 ic2
TIM5_SMCR |= 0X04; // 选源触发源和触发方式 复位
TIM5_IER |= 0x0a; // 使能中断ch1 ch3
TIM5_CCER1 |= 0x01; // 使能输入捕获 1
TIM5_CCER2 |= 0X01; // 使能输入捕获 3 1111 1101
TIM5_CNTRH = TIM5_CNTRL = 0;
TIM5_CR1 = 0x03; // Enabled update request source;Counter enabled;
}
#pragma vector = TIM5_CAPCOM_TIF_vector
__interrupt void TIM5_CAPCOM_TIF(void)
{
static unsigned int i = 0,j = 0;
//i = (unsigned int)(8<<TIM5_CCR3H);
//i |= (unsigned int)(TIM5_CCR3L);
if(TIM5_SR1 & 0x02) //红外
{
if( TIM5_CCER1 & 0x02) //下降沿产生的中断
{
i = 0;
i = ( TIM5_CCR1H << 8 );
i |= TIM5_CCR1L;
//TIM5_CNTRH = TIM5_CNTRL = 0;
TIM5_CCER1 &=~ 0x02; //改为上升沿捕获
}
else //上升沿产生的中断
{
j = 0;
j = ( TIM5_CCR1H << 8 );
j |= TIM5_CCR1L;
//TIM5_CNTRH = TIM5_CNTRL = 0;
TIM5_CCER1 |= 0x02; //改为下降沿捕获
//uiTenor |= TM1_CAP_FLAG; //一段低电平时间捕获
}
TIM5_CNTRH = 0;
TIM5_CNTRL = 0;
}
if(TIM5_SR1 & 0x08) //FG
{
if(TIM5_CCER2 & 0x02) //下降沿产生的中断
{
i = ( TIM5_CCR3H << 8 );
i |= TIM5_CCR3H;
TIM5_CCER2 &=~ 0x02; //改为上升沿捕获
}
else //上升沿产生的中断
{
j = (TIM5_CCR3H << 8);
j |= TIM5_CCR3L;
TIM5_CCER2 |= 0x02; //改为下降沿捕获
//uiTenor |= TM1_CAP_FLAG; //一段低电平时间捕获
}
}
}//*/
TIM5_CCR1H和TIM5_CCR1L的值读出来不对,不管怎么调整预分频系数TIM5_CCR1H和TIM5_CCR1L的值都不会变化,求大师指点。 |