《电子技术应用》
您所在的位置:首页 > 模拟设计 > 解决方案 > LC7461红外遥控器和解码程序

LC7461红外遥控器和解码程序

2016-12-19
关键词: 红外遥控 解码

LC7461红外遥控器和解码程序

//遥控解码子程序,LC7461,用户码为11C
//external interrupt0
void isr_4()
{

 unsigned char r_count;//定义解码的个数
 unsigned long use_data=0;//定义16位的用户码,只用到13位
 unsigned long use_code=0;//定义16位的用户反码,只用到13位
 unsigned long data=0;//定义16位数据码,包括8位数据码和反码
 unsigned char data_h=0;//数据反码
 unsigned char data_l=0;//数据码
 _clrwdt();
// _delay(7000);//7461解码,延时7000
// _delay(7000);//7461解码,延时7000
//_delay(7000);//7461解码,延时7000
 if(remote==1)
  goto error;
 while(remote==0);//wait to high
 //_delay(9744);
count_delay=0;
 while(count_delay<143);
 if(remote==1)
  goto error;
     /////用户码解码use_data//////////add//////////////////////////
     for(r_count=13;r_count>0;r_count--)
  {
  while(remote==0);//wait to high
  count_delay=0;
     while(count_delay<24);//_delay(1680);
  _c=remote;
  if(_c==1)
   {
   _lrrc(&use_data);
   count_delay=0;
         while(count_delay<32);//_delay(2200);//wait to low
   }
  else
   _lrrc(&use_data);
  }
  _nop();
 //if(remote==1)
  //_delay(1680);//wait to low while(remote==1);//wait to low
     _nop();
     ////////用户码解码finish/////////add/////////add////////
     /////用户码反码解码use_code//////////add//////////////////////////
     for(r_count=13;r_count>0;r_count--)
  {
  while(remote==0);//wait to high
  count_delay=0;
         while(count_delay<24);//_delay(1680);
  _c=remote;
  if(_c==1)
   {
   _lrrc(&use_code);
   count_delay=0;
         while(count_delay<32);//_delay(2200);//wait to low
   }
  else
   _lrrc(&use_code);
  }
 _nop();
 //if(remote==1)
 // _delay(1680);//wait to low while(remote==1);//wait to low
     _nop();
     ////////用户码反码解码finish/////////add/////////add////////
     ////数据码解码开始////data_l为用户码,data_h为数据码反码////////////
 for(r_count=16;r_count>0;r_count--)
  {
  while(remote==0);//wait to high
  count_delay=0;
         while(count_delay<24);//_delay(1680);
  _c=remote;
  if(_c==1)
   {
   _lrrc(&data);
   count_delay=0;
         while(count_delay<32);//_delay(2200);//wait to low
   }
  else
   _lrrc(&data);
  }
 ////数据码解码结束////////////////////////////////////////////////
 data_l=data;
 data_h=data>>8;
 ///用户码//////
 use_data>>=3;
 use_code>>=3;
 use_code=~use_code;
 ////////
 ////如果用户码等与0x11c并且数据码和数据反码都校验一致,解码成功
 //if((~data_h==data_l)&&use_data==0x11c)//使用用户码
 //跳过用户码
 if(~data_h==data_l)//如果数据码和数据反码(取反后)相等,解码正确
  {
  _nop();
  r_data=data_l;//r_data为解出的最终数据码
  }
 //否则解码不成功
 _nop();
 _nop();
error:  //r_data=nocode;
 _nop();
    _nop();
 _nop();
}

本站内容除特别声明的原创文章之外,转载内容只为传递更多信息,并不代表本网站赞同其观点。转载的所有的文章、图片、音/视频文件等资料的版权归版权所有权人所有。本站采用的非本站原创文章及图片等内容无法一一联系确认版权者。如涉及作品内容、版权和其它问题,请及时通过电子邮件或电话通知我们,以便迅速采取适当措施,避免给双方造成不必要的经济损失。联系电话:010-82306118;邮箱:aet@chinaaet.com。