//=======================================================================================
/*T1捕获中断*/
#pragma vector= ITC_IRQ_TIM1_CAPCOM+2
__interrupt void TIM1_CAP_COM(void)
{
Ulong Rn01,Rn02; Uchar i;
/*========================数据处理=================================================*/
IrInter.Rn++; //上升沿或下降沿捕获标志
if(IrInter.Rn==1)//120170707
{
IrInter.PeriT1=TIM1_GetCounter(); //读捕获值(上升沿)
Rn01=IrInter.Update; //溢出次数
IrInter.Update=0; //清溢出次数
Rn01<<=16;
IrInter.PeriT1+=Rn01;
IrInter.PeriTa=IrInter.PeriT1-IrInter.PeriT2; //得出低电平时间
TIM1_ICInit(TIM1_CHANNEL_3, //通道1
TIM1_ICPOLARITY_FALLING, //下降沿触发
TIM1_ICSELECTION_DIRECTTI, //IC1映射在TI1FP1上
TIM1_ICPSC_DIV1, //捕捉1分频
0x00); //滤波0
}
else if(IrInter.Rn==2)//0
{
IrInter.Rn=0;
IrInter.PeriT2=TIM1_GetCounter(); //读捕获值(下降沿)
Rn02=IrInter.Update; //溢出次数
IrInter.Update=0; //清溢出次数
Rn02<<=16;
IrInter.PeriT2+=Rn02;
IrInter.PeriTb=IrInter.PeriT2-IrInter.PeriT1; //得出高电平时间
TIM1_ICInit(TIM1_CHANNEL_3, //通道1
TIM1_ICPOLARITY_RISING, //上升沿触发
TIM1_ICSELECTION_DIRECTTI, //IC1映射在TI1FP1上
TIM1_ICPSC_DIV1, //捕捉1分频
0x00); //滤波0
}
//==============================解码处理================================================== IrInter.Rn==1才是接收了正确的Ta,Tb
if(/*(WorkStateBit.Bit.IrInStatEn==1)&&*/(IrInter.Rn==1)&&(IrInter.PeriTb>280)&&(IrInter.PeriTb<350)&&(IrInter.PeriTa>8000)&&(IrInter.PeriTa<11000)) //判头码 170 255 5950 6300
{//开始
IrInter.HeadCode=1; //正确接收到头码
IrInter.DataPiont=(Uchar*)&Irdata.DM1; //取指针地址
IrInter.Ri0=0; //计每个字节位数
IrInter.Ri1=0; //计字节数
}
//--------------------------头码正确-------------------------------------------------------
else if((IrInter.HeadCode==1)&&(IrInter.Rn==1)&&(IrInter.PeriTb>280)&&(IrInter.PeriTb<1200)) //检数据时间译码
{
if(IrInter.PeriTb>800)//500(1000)
{*IrInter.DataPiont|=Db[IrInter.Ri0];} //高为1
else
{*IrInter.DataPiont&=~Db[IrInter.Ri0];}//低为0
if(++IrInter.Ri0 >=8) //收够8位数据指针加1,进1个字节
{
IrInter.Ri0=0; //接收计位数
IrInter.Ri1++; //接收计字节数
IrInter.DataPiont++; //接收指针加1
if(IrInter.Ri1 ==3)//收够3个字节(看数据长度来修改)
{
Tx=~Tx;
IrInter.DataPiont=(Uchar*)&Irdata.DM1; //取缓存指针地址
IrInter.Rn01++; //每次接收3个数据包
switch (IrInter.Rn01)
{
case 1: IrInter.DataPiontA=(Uchar*)&IrdataA.DM1; //取数据A指针地址
; break;
case 2: IrInter.DataPiontA=(Uchar*)&IrdataA.DM1+4; //取数据A指针地址+4
; break;
case 3: IrInter.Rn01=0;
IrInter.DataPiontA=(Uchar*)&IrdataA.DM1+8; //取数据A指针地址+8
; break;
}
for(i=0;i<3;i++) //
{
*IrInter.DataPiontA++=*IrInter.DataPiont++; //将缓存数据存入寄存器
}
if((IrdataA.DM1==IrdataA.DM5)&&(IrdataA.DM2==IrdataA.DM6)&&(IrdataA.DM3==IrdataA.DM7))
{
if((IrdataA.DM1==IrdataA.DM9)&&(IrdataA.DM2==IrdataA.DM10)&&(IrdataA.DM3==IrdataA.DM11))
{
IrInter.Receive_OK=1; //3个包接收OK
//WorkStateBit.Bit.IrInStatEn=0; //关接收
IrEep.IrRn++;
IrEep.KongTime=0;
if((IrXueXiBit.Bit.KongBit==1)&&(WorkStateBit.Bit.ZhengChangRunEn==1)&&(IrdataA.DM1==IrdataB.DM1)&&(IrdataA.DM2==IrdataB.DM2)&&(IrdataA.DM3==IrdataB.DM3))
{
Moto.Rn++;
IrXueXiBit.Bit.KongBit=0;
MotoStateBit.Bit.YiChuLi=1;
}
}
}
IrInter.HeadCode=0; //清头码标志
}
}
}
//================================================================================
/*-------------------------------------------------------------------------*/
TIM1_ClearITPendingBit(TIM1_IT_CC3); //清除捕获比较3中断标志
}
//================================================================================
离线
解码各种433Mhz 遥控器,安防设备信号。
离线