⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_one.c

📁 用C语言写的红外遥控解码程序
💻 C
字号:
/* 遥控外部0中断******************************/
void int0remoter() interrupt 0
{
    TR1 = 0;//停止计时
    if(((TL1+TH1*256) == 0) || (connt >= 33))
    {
        connt = 0;
        TH1 = 0;
        TL1 = 0;
        TR1 = 1;
        return; //遥控第一次下降沿中断
    }

    if(connt == 0 )
    {
        if(((TL1+TH1*256) > (13500-DELTA)) && ((TL1+TH1*256) < (13500+DELTA)))
        {
            connt++;
            TH1 = 0;
            TL1 = 0;
            TR1 = 1;
            return;//成功测到红外头,加1退出中断
        }
        connt = 0;
        TR1 = 0;
        TH1 = 0;
        TL1 = 0;
        return;//没有测到正确红外头,清0退出中断
    }
    if(connt != 0)
    {
        if(connt <= 8)
        {
            if(((TL1+TH1*256) > (1125-DELTA)) && ((TL1+TH1*256) < (1125+DELTA)))
            {
                ir_data1 >>= 1;
                connt++;
                TH1 = 0;
                TL1 = 0;
                TR1 = 1;
                return;//读到0退出中断
            }
            if(((TL1+TH1*256) > (2250-DELTA)) && ((TL1+TH1*256) < (2250+DELTA)))
            {
                ir_data1 >>= 1;
                ir_data1 |= 0x80;
                connt++;
                TH1 = 0;
                TL1 = 0;
                TR1 = 1;
                return;//读到1退出中断
            }
            connt = 0;
            TR1 = 0;
            TH1 = 0;
            TL1 = 0;
            return;//错误,清0退出中断
        }
        if(connt > 8 && connt <=16)
        {
            if(((TL1+TH1*256) > (1125-DELTA)) && ((TL1+TH1*256) < (1125+DELTA)))
            {
                ir_data2 >>= 1;
                connt++;
                TH1 = 0;
                TL1 = 0;
                TR1 = 1;
                return;//读到0退出中断
            }
            if(((TL1+TH1*256) > (2250-DELTA)) && ((TL1+TH1*256) < (2250+DELTA)))
            {
                ir_data2 >>= 1;
                ir_data2 |= 0x80;
                connt++;
                TH1 = 0;
                TL1 = 0;
                TR1 = 1;
                return;//读到1退出中断
            }
            connt = 0;
            TR1 = 0;
            TH1 = 0;
            TL1 = 0;
            return;//错误,清0退出中断
        }
        if(connt > 16 && connt <=24)
        {
            if(((TL1+TH1*256) > (1125-DELTA)) && ((TL1+TH1*256) < (1125+DELTA)))
            {
                ir_data3 >>= 1;
                connt++;
                TH1 = 0;
                TL1 = 0;
                TR1 = 1;
                return;//读到0退出中断
            }
            if(((TL1+TH1*256) > (2250-DELTA)) && ((TL1+TH1*256) < (2250+DELTA)))
            {
                ir_data3 >>= 1;
                ir_data3 |= 0x80;
                connt++;
                TH1 = 0;
                TL1 = 0;
                TR1 = 1;
                return;//读到1退出中断
            }
            connt = 0;
            TR1 = 0;
            TH1 = 0;
            TL1 = 0;
            return;//错误,清0退出中断
        }
        if(connt > 24 && connt <= 32)
        {
            if(((TL1+TH1*256) > (1125-DELTA)) && ((TL1+TH1*256) < (1125+DELTA)))
            {
                ir_data4 >>= 1;
                connt++;
                TH1 = 0;
                TL1 = 0;
                TR1 = 1;
                if(connt == 33)
                    ir_succeed();
                return;//读到0退出中断
            }
            if(((TL1+TH1*256) > (2250-DELTA)) && ((TL1+TH1*256) < (2250+DELTA)))
            {
                ir_data4 >>= 1;
                ir_data4 |= 0x80;
                connt++;
                TH1 = 0;
                TL1 = 0;
                TR1 = 1;
                if(connt == 33)
                    ir_succeed();
                return;//读到1退出中断
            }
            connt = 0;
            TR1 = 0;
            TL1 = 0;
            TH1 = 0;
            return;//错误,清0退出中断
        }
    }
}        
void ir_succeed()
{   
     if(1)//(IR_SYSCODE1 == ir_data1) && (IR_SYSCODE2 == ir_data2))
     {
          if(ir_data3 == (0xff - ir_data4))
          {   ir_data = ir_data3;
              ir_enable = 1;
          }
                
     }
}
void timer1_int() interrupt 3
{
    connt = 0;
    TR1 = 0;
    TH1 = 0;
    TL1 = 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -