下面是我输入捕获的代码
void Timer2Capture_Init(void)
{
P01_Input_Mode;
P01 = 1;
TIMER2_CAP0_Capture_Mode;
IC4_P01_CAP0_BothEdge_Capture;
// set_ET2; //Enable Timer2 interrupt
set_ECAP; //Enable Capture interrupt
set_TR2; //Triger Timer2
set_EA;
}
void Capture_ISR (void) interrupt 12
{
// uint16_t Pulse;
clr_CAPF0;
// NumberL = C0L; // For capture mode CxL/CxH with data capture from I/O pin
// NumberH = C0H;
Pulse = C0H;
Pulse <<= 8;
Pulse |= C0L;
printf("\n Single 0x%04X",Pulse);
DataAnalyze();
clr_TF2;
}
void DataAnalyze()
{
Time = Pulse/16;//这里做了下运算输入捕获的值就不准了,如果不做运算就可以。
printf("\n TM2 Time %u",Time);
a=Pulse;
// cc =1;
if((a>=7520)&&(a<=8480))
{
// Single = 0X3F; //½ÓÊÕµ½0
printf("\n 0000000 0x%bX",0X3F);
}
if((a>=3520)&&(a<=4320))
{
// Single = 0X01; //½ÓÊÕµ½0
printf("\n 111111 0x%bX",0X01);
}
} |