搜索
bottom↓
回复: 8

有关飞利浦RC6格式的红外编码程序的问题

[复制链接]

出0入0汤圆

发表于 2010-9-20 10:14:03 | 显示全部楼层 |阅读模式
在网上搜了,RC6格式的红外编码资料很少,找到一个解码程序,思路大致明白,但中间还有些不解,请大家帮帮忙!
解码程序如下:
/*
定时器0中断函数
中断间隔:200us
*/

void Isr_Timer0()
{
shift_ir:
        if(ir_shift_flag)
        {
                ir_shift_flag = 0;        
            _rlc(&ir_data0);
            _rlc(&ir_data1);
            _rlc(&ir_data2);
          if(ir_bit >= 21)
          {        
                  if((ir_usercode == ir_data1) && (ir_value == ir_data0))
                         {
                                 ir_ok = 1;
                         }
                         else
                         {        
                         ir_usercode = ir_data1;
                         ir_value = ir_data0;
                  }
err_ir:
            ir_head = 0;
            ir_bit = 0;
            ir_data0 = 0;
            ir_data1 = 0;
            ir_data2 = 0;
            bit_over = 0;
            ir_shift_flag = 0;         
          }        
            return;
         }   
               
        ir_ltime++;
        ir_htime++;
        if(IR_IN)
        {
                if(!ir_pin_level)
                {
                        ir_pin_level = 1;   //ir电平从低变高
                        ir_ltime_temp = ir_ltime;
                        ir_htime = 0;
                        if(ir_head)
                        {
                                if(ir_ltime > 3)
                                {
                                        if(bit_over)
                                                goto err_ir;
                                        else
                                        {
                                                if(ir_bit == 5)
                                                {
                                                        if(ir_ltime > 5)     //判断奇偶位为0时的低电平
                                                        {
                                                                                
                                                   _c = 1;
                                                   ir_bit++;
                                                   ir_shift_flag = 1;
                                                   goto shift_ir;
                                            }
                                            else
                                            {
                                                    bit_over = 1;
                                            }
                                           }
                                           else
                                           {
                                                   _c = 1;
                                                   ir_bit++;
                                                   ir_shift_flag = 1;
                                                   goto shift_ir;
                                                 }         
                                                            
                                        }
                                }
                                else
                                {
                                        if(bit_over)
                                        {
                                                bit_over = 0;
                                                _c = 1;
                                                ir_bit++;
                                                ir_shift_flag = 1;
                                                goto shift_ir;
                                        }
                                        else
                                                bit_over = 1;
                                }                                                                                
                        }
               
                }
               
        }
        else
        {
                if(ir_pin_level)
                {
                        ir_pin_level = 0; //ir电平从高变低
                        ir_htime_temp = ir_htime;
                        ir_ltime = 0;        
                        if(ir_head)
                        {
                                if(ir_htime > 3)
                                {
                                        if(bit_over)
                                        {
                                                if(ir_bit == 4)
                                                {
                                                        bit_over = 0;         //判断奇偶位是0时的高电平
                                                                _c = 0;
                                                    ir_bit++;
                                                    ir_shift_flag = 1;
                                                    goto shift_ir;
                                                  }
                                                 else
                                                         goto err_ir;
                                                }
                                                
                                        else
                                        {
                                                if(ir_bit == 5)
                                                {
                                                        if(ir_htime < 5)       //判断奇偶校验位是1时的高电平
                                                        {
                                                                bit_over = 1;
                                                        }
                                                        else
                                                 {
                                                                 _c = 0;
                                                    ir_bit++;
                                                    ir_shift_flag = 1;
                                                    goto shift_ir;
                                                  }
                                                }
                                                else
                                                {
                                                        _c = 0;
                                                    ir_bit++;
                                                    ir_shift_flag = 1;
                                                    goto shift_ir;
                                                  }
                                                                  
                                        }
                                }
                                else
                                {
                                        if(bit_over)
                                        {
                                                bit_over = 0;
                                                _c = 0;
                                                ir_bit++;
                                                ir_shift_flag = 1;
                                                goto shift_ir;
                                                
                                        }
                                        else
                                                bit_over = 1;                                                
                                }               
                                                
                        }
                        else
                        {
                                if((ir_ltime_temp > 11) && (ir_ltime_temp < 16))               
                                {
                                        ir_head = 1;   //检测到头码
                                        bit_over = 1;
                                       
                                }
                                else
                                        goto err_ir;
                        }                                
                                       
                  }        
          }               
}
/******************end****************/
有两个疑问:(1)_rlc(&ir_data0);
                 _rlc(&ir_data1);
                 _rlc(&ir_data2);这三条语句什么意思呢?
            (2) if(IR_IN)
                  {
                      if(!ir_pin_level)
                      {
                           ir_pin_level = 1;   //ir电平从低变高
                  这个地方看不懂,不知道  IR_IN   ir_pin_level   什么关系,   问什么  ir_pin_level=1  就能说  ir电平从低变高呢?
            希望高手帮忙解答下,小生不胜感激。

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入0汤圆

 楼主| 发表于 2010-9-20 10:32:58 | 显示全部楼层
没人解过RC6红外编码吗?自己顶!

出0入0汤圆

发表于 2010-9-20 11:17:16 | 显示全部楼层
不就是算时间?

出0入0汤圆

 楼主| 发表于 2010-9-20 11:23:56 | 显示全部楼层
RC6格式属于PPM(脉冲位置调制)方式,与NEC不同的。

出0入0汤圆

发表于 2010-9-20 22:41:50 | 显示全部楼层
帮你顶

出0入0汤圆

发表于 2016-6-3 19:21:30 | 显示全部楼层
本帖最后由 mathison 于 2016-6-3 19:26 编辑

贴一个 我做好的 供大家参考


//PHILIPS RC6

#define CONST_IR_BITCOUNT     16

unsigned char OverFlowCount;           //   
unsigned char IR_BitCount;             //   
unsigned char IR_Code[4];              //   

#define RC6_1T_MIN                 103  //136 -/+ 13
#define RC6_1T_MAX                 170

#define RC6_2T_MIN                 231  //136 X2 -/+26
#define RC6_2T_MAX                 313

#define RC6_3T_MIN                 353  //136 X3 -/+ 40
#define RC6_3T_MAX                 463

#define RC6_4T_MIN                 570   //136 X4 -/+ 55
#define RC6_4T_MAX                 622

#define RC6_5T_MIN                 645
#define RC6_5T_MAX                 715

#define RC6_6T_MIN                 766
#define RC6_6T_MAX                 866

bit IR_SyncFlag;                       //   




void remote_init(void)
{
    GPIO24_CFG_SAMPLE;                       //   
    //SMCON = SMEN | SMOE | SMMD_1 | SMCKS_0;  //   
    SMCON = SMEN | SMOE | SMMD_2 | SMCKS_0;  //  
    SMDIV = 6;                               //   
    SMVTHL = (SYN_WIDTH1 * 2) % 256;             //   
    SMVTHH = (SYN_WIDTH1 * 2) / 256;
    SMCON |= SMIE;
    EINT9 = 1;               //  
    EA = 1;

    IR_SyncFlag = 0;
    OverFlowCount = 0;
}

volatile bit bFlag_data = 0;

volatile bit bFlag_Mode = 0;
volatile bit bFlag_start = 0;
volatile bit bFlag_pre_bit = 1;
volatile unsigned char IR_RC6_1T_Count;

void INT9_ISR (void) interrupt 14
{
    unsigned int PulseWidth;

    if(SMSTA & SMEF)
    {
        SMSTA |= SMEF;

        if(OverFlowCount == 0)
        {
            PulseWidth = (SMDATH & 0x7F) * 256 + SMDATL; //   

            if(!IR_SyncFlag)
            {
                if((PulseWidth > RC6_6T_MIN) && (PulseWidth < RC6_6T_MAX))    //   
                {
                    IR_SyncFlag = 1;
                    IR_BitCount = 0;
                    bFlag_start = 1;
                    bFlag_Mode = 0;
                    bFlag_data = 0;

                }
            }
            else if(bFlag_start)
            {
                if((PulseWidth > RC6_2T_MIN) && (PulseWidth < RC6_2T_MAX)) //START
                {
                    bFlag_start = 0;
                    bFlag_Mode = 1;
                    bFlag_pre_bit = 1;
                    IR_RC6_1T_Count = 0;
                    IR_BitCount = 0;

                }
                else
                {
                    IR_SyncFlag = 0;          //   
                    bFlag_start = 0;
                    bFlag_Mode = 0;
                    bFlag_data = 0;
                    IR_BitCount = 0;

                }
            }
            else if(bFlag_Mode) //Field
            {
                ++IR_RC6_1T_Count;

                if((PulseWidth > RC6_1T_MIN) && (PulseWidth < RC6_1T_MAX))
                {


                    if(IR_RC6_1T_Count & 0x01)
                    {


                        if(bFlag_pre_bit)
                        {
                            IR_Code[IR_BitCount / 8] |= (1 << (7 - (IR_BitCount % 8)));
                            //IR_BitCount++;
                        }
                        else
                        {
                            IR_Code[IR_BitCount / 8] &= ~(1 << (7 - (IR_BitCount % 8)));
                            //IR_BitCount++;
                        }

                        IR_BitCount++;
                    }

                }
                else if((PulseWidth > RC6_2T_MIN) && (PulseWidth < RC6_2T_MAX))
                {
                    if(IR_RC6_1T_Count & 0x01)  // 很重要
                    {
                        ;
                    }
                    else
                    {
                        bFlag_pre_bit = ~bFlag_pre_bit;
                    }

                    ++IR_RC6_1T_Count;


                    if(IR_BitCount < 4 )
                    {


                        if(bFlag_pre_bit)
                        {
                            IR_Code[IR_BitCount / 8] |= (1 << (7 - (IR_BitCount % 8)));
                            //IR_BitCount++;
                        }
                        else
                        {
                            IR_Code[IR_BitCount / 8] &= ~(1 << (7 - (IR_BitCount % 8)));
                            //IR_BitCount++;
                        }

                        IR_BitCount++;

                        //bFlag_pre_bit = ~bFlag_pre_bit;
                        if(IR_RC6_1T_Count & 0x01)  //很重要
                        {
                            ;
                        }
                        else
                        {
                            bFlag_pre_bit = ~bFlag_pre_bit;
                        }
                    }
                    else
                    {
                        if(IR_RC6_1T_Count == 12)
                        {
                            IR_RC6_1T_Count = 0;
                            IR_Code[IR_BitCount / 8] &= ~(1 << (7 - (IR_BitCount % 8))); //"0"
                            IR_BitCount = 7;

                            IR_BitCount++;
                            bFlag_pre_bit = 0;
                            bFlag_Mode = 0;
                            bFlag_data = 1;

                        }


                    }
                }
                else if((PulseWidth > RC6_3T_MIN) && (PulseWidth < RC6_3T_MAX))
                {

                    ++IR_RC6_1T_Count;
                    ++IR_RC6_1T_Count;

                    if(IR_RC6_1T_Count >= 12)
                    {
                        IR_RC6_1T_Count = 0;
                        IR_Code[IR_BitCount / 8] |= (1 << (7 - (IR_BitCount % 8))); //"1"

                        IR_BitCount = 7;

                        IR_BitCount++;

                        IR_Code[IR_BitCount / 8] &= ~(1 << (7 - (IR_BitCount % 8)));
                        IR_BitCount++;
                        ++IR_RC6_1T_Count;

                        bFlag_pre_bit = 0;
                        bFlag_Mode = 0;
                        bFlag_data = 1;

                    }

                }
                else
                {
                    IR_SyncFlag = 0;          //   
                    bFlag_start = 0;
                    bFlag_Mode = 0;
                    bFlag_data = 0;
                    IR_BitCount = 0;

                }
            }
            else if(bFlag_data)
            {


                ++IR_RC6_1T_Count;

                if((PulseWidth > RC6_1T_MIN) && (PulseWidth < RC6_1T_MAX))
                {


                    if(IR_RC6_1T_Count & 0x01)
                    {


                        if(bFlag_pre_bit)
                        {
                            IR_Code[IR_BitCount / 8] |= (1 << (7 - (IR_BitCount % 8)));
                        }
                        else
                        {
                            IR_Code[IR_BitCount / 8] &= ~(1 << (7 - (IR_BitCount % 8)));
                        }

                        IR_BitCount++;
                    }

                }
                else if((PulseWidth > RC6_2T_MIN) && (PulseWidth < RC6_2T_MAX))
                {

                    if(IR_RC6_1T_Count & 0x01)  //非常重要
                    {
                        ;
                    }
                    else
                    {
                        bFlag_pre_bit = ~bFlag_pre_bit;
                    }

                    ++IR_RC6_1T_Count;

                    if(bFlag_pre_bit)
                    {
                        IR_Code[IR_BitCount / 8] |= (1 << (7 - (IR_BitCount % 8)));
                    }
                    else
                    {
                        IR_Code[IR_BitCount / 8] &= ~(1 << (7 - (IR_BitCount % 8)));
                    }

                    IR_BitCount++;

                    //bFlag_pre_bit = ~(bFlag_pre_bit); // 非常重要     
                    if(IR_RC6_1T_Count & 0x01)
                    {
                        ;
                    }
                    else
                    {
                        bFlag_pre_bit = ~bFlag_pre_bit;
                    }
                }

                else
                {
                    IR_SyncFlag = 0;          //   
                    bFlag_start = 0;
                    bFlag_Mode = 0;
                    bFlag_data = 0;

                }



                if((IR_BitCount == (CONST_IR_BITCOUNT + 8)) && IR_SyncFlag)   //  
                {
                    IR_SyncFlag = 0;
#if 1
                    //接收接收  串口打印结果
                    S0BUF = 0xBB;

                    while(!TI0);

                    TI0 = 0;
                    S0BUF = IR_Code[0];

                    while(!TI0);

                    TI0 = 0;
                    S0BUF = IR_Code[1];

                    while(!TI0);

                    TI0 = 0;
                    S0BUF = IR_Code[2];

                    while(!TI0);

                    TI0 = 0;
                    S0BUF = IR_Code[3];

                    while(!TI0);

                    TI0 = 0;
#endif
                }
            }
        }

        irc_break_timer = 12;
        OverFlowCount = 0;               //   
    }

    if(SMSTA & SMOF)
    {
        SMSTA |= SMOF;

        if(OverFlowCount < 0xFF)
        {
            OverFlowCount++;            //   
        }
    }
}

出0入0汤圆

发表于 2016-6-4 08:49:52 来自手机 | 显示全部楼层
双沿触发 计算脉宽
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-6-9 14:46

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表