void Timer1Config(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_DOWN, 10000, 0);
TIM1_ICInit(TIM1_CHANNEL_1, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV8, 0x0);
TIM1_ITConfig(TIM1_IT_CC1, ENABLE);
TIM1_ClearFlag(TIM1_FLAG_CC1);
TIM1_Cmd(ENABLE);
}
这里是我的初始化函数。
#ifdef _COSMIC_
@far @interrupt void TIM1_CAP_COM_IRQHandler(void)
#else /* _RAISONANCE_ */
void TIM1_CAP_COM_IRQHandler(void) interrupt 12
#endif /* _COSMIC_ */
{
u8 DataCnt = SetZero;
u16 TempVale = SetZero;
if (TIM1_GetITStatus(TIM1_IT_CC1))
{
TIM1_ClearFlag(TIM1_FLAG_CC1);
tab = ta/10;
ta++;
switch(tab)
{
case 0:
a[tabc++] = TIM1_GetCapture1();;
break;
case 1:
if (ta==11)
tabc = 0;
b[tabc++] = TIM1_GetCapture1();;
break;
case 2:
if (ta==21)
tabc = 0;
c[tabc++] = TIM1_GetCapture1();;
break;
case 3:
if (ta==31)
tabc = 0;
d[tabc++] = TIM1_GetCapture1();;
nop();
break;
case 4:
if (ta==41)
tabc = 0;
e[tabc++] = TIM1_GetCapture1();;
break;
case 5:
if (ta==51)
tabc = 0;
f[tabc++] = TIM1_GetCapture1();;
break;
default:
tab = 0;
ta = 0;
tabc = 0;
break;
}
}
这里是我的中断服务函数。
我捕获的脉冲是周期1KHZ的方波(信号发生器出来的)
但是在程序抓出来确是2000,我认为正确应该是1000才对; |