TCOOP-M101-433M发射模块-HS2245遥控器解码应用手册

创建时间:2023-02-10 17:19
浏览量:0

u8    LR43B_FLAG=0;

u8    LR43B_COUNT=0;

u8    LR43B_STATUS=0;

u16   LR43B_HIGH_COUNT=0;

u16   LR43B_LOW_COUNT=0;

u32   LR43B_DATA1=0;

 

//无线遥控模块

//100us延时函数

void LR43B_SCAN(void)

{

   // 1:读取高低电平持续的时间

 if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_13 ))

 {

  bit_set(LR43B_FLAG,0);

  LR43B_HIGH_COUNT++;

}

 else

 {

   bit_set(LR43B_FLAG,1);

  LR43B_LOW_COUNT++;

 }

 

 if(LR43B_FLAG==3)

 {

  LR43B_COUNT++;

  LR43B_FLAG=0;

   //2:搜寻每段波形的开头

  if(((LR43B_HIGH_COUNT>30)&&(LR43B_HIGH_COUNT<40)))

  {

     bit_set(LR43B_STATUS,0); //开始标志

     LR43B_COUNT=0;

  }

  

  //3:将前进/后退信号的前32位数对应置01

  if(LR43B_COUNT&&btfss(LR43B_STATUS,0))

  {

   if(LR43B_COUNT>=2&&LR43B_COUNT<=64)

   {

    //根据高电平时间判断该位数据置0还是置1LR43B_COUNT为偶数时为高电平

    if(LR43B_COUNT%2==0)

    {

     if(LR43B_HIGH_COUNT<4)  bit_clr(LR43B_DATA1,32-LR43B_COUNT/2);

     else  bit_set(LR43B_DATA1,32-LR43B_COUNT/2);

    }

   }

  }

 

  if(LR43B_COUNT==64&&btfss(LR43B_STATUS,0))

  {

   //4:校验高8

   if(LR43B_DATA1>>24==0x49)

    {  

     //5:得到最后具体数据

     RF_DATA= LR43B_DATA1;//最终得到值

     // RF_DATA==0x49910C05前进

     // RF_DATA= 0x49910C03后退

    }

    LR43B_STATUS=0;

    LR43B_DATA1=0;  

   }

    LR43B_HIGH_COUNT=0;

   LR43B_LOW_COUNT=0;

  }

}