找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3856|回复: 0
打印 上一主题 下一主题
收起左侧

红外线遥控码单片机测试程序

[复制链接]
跳转到指定楼层
#
ID:101489 发表于 2016-1-2 20:40 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
转自:http://www.51hei.com/mcu/1488.html
以前在仕创时,总是奇怪 周工为什么可以编出一个能测试任何遥控的遥控码 和用户码的单片机程序!周工还将此程序视为宝贝,每次测试完都将那只已经烧录好的单片机拿回去!!在这几年 本人也接触单片机,尝试写出测试遥控码的程序!!但只是能测试出遥控码 并未能测试出用户码!!!所以当时周工还是相当厉害的!!
       下面放出刚刚编录完成的程序,暂时只能测试遥控码!!
     下载地址:http://www.51hei.com/f/hw51d.rar

下载软件界面,用于烧录单片机!!




USB下载器

刚烧录好程序,单片机加电时显示“00”

测试遥控码(家里电视机待机按键遥控码)

程序是由C语言编写,单片机使用AT89C52       下面是程序:

#include<reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long

#defineNop(){_nop_(); _nop_(); _nop_(); _nop_(); _nop_();}

volatile ulong IRcode=0x00000000;  
volatile ulong Irdcode=0x00000000;
volatile uint customcode=0x0000;      
volatile uint time_us=0x0000;      

volatile uchar timeH,timeL;  

uchar Lcustomcode;      
uchar Hcustomcode;     
uchar datacode;   
uchar mycode;
uchar Rdatacode;      
uchar uc1ms;
uchar uc10ms;
uchar uc3ms;

uchar  ucDispTime;
uchar  ucDispOrder;
uchar  ucDispCon;
uchar ucSpeakerTime;
unsigned char code LedData[16] = { 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
unsigned char code LedCon[2] = {0x8f,0x4f};
unsigned char ucDispData[2];
sbit led1 = P3^7;
sbit led2 = P3^6;
sbit power=P1^0;  
sbit BEEP= P2^1;
bit NewIRcode=0;  
bit DataRight=0;   
bit bSampleOk;
bit bSampling;
bit b10msInt;
bit  b1msInt;
bit bKeySound;
bit b1msMain;
bit IR_E;           
bit b3msint;

void SendDataToDispDevice();
void Ir_process();
void display();
void beeping();

void init()
{
  IP=0x09;   
  TMOD=0x11;
  TCON=0x01;
  TH0=0xff;  
  TL0=0x47;
  TH1=0x00;  
  TL1=0x00;

  EA=1;   
  ET0=1;   
  ET1=1;      
  EX0=1;   
  TR1=0;
  TR0=1;

}

void TimeProg(void)
{      
b1msMain = b1msInt;
   b1msMain=0;
b10msInt = 0;


if(b1msInt == 1)
{  
         b1msMain=1;
   if(++uc10ms == 10)
{
uc10ms = 0;
b10msInt = 1;
if(bKeySound==1)
  {beeping();
bKeySound=0;
}
}

}
}//void TimeProg(void)

void IR_ISR() interrupt 0 using 1
{
  static uchar cn;

  TR1=0;
  timeH=TH1;
  timeL=TL1;
  TH1=0;
  TL1=0;
  TR1=1;                     

  time_us=(unsigned int)timeH;
  time_us=time_us<<8;
  time_us=time_us|timeL;

  if(time_us>12200&&time_us<13000) {cn=1;IRcode=0;}  
  if(cn<34)
      {
          if(time_us>950&&time_us<1120)                   //0
           {
             IRcode=IRcode|0x00000000;
             if(cn<33) IRcode=IRcode>>1;
           }

      else if(time_us>1920&&time_us<2120)        //1t > 1950 && t < 2150
          {
             IRcode=IRcode|0x80000000;
             if(cn<33) IRcode=IRcode>>1;
           }
  

  //else if(time_us>10000&&time_us<11000) {Irdcode=IRcode;cn=34; }   
                                                   }
cn++;
  if(cn==34)
   { NewIRcode=1;
     TR1=0;  

     Irdcode= IRcode;  cn=0;  
}  

}


void Timer0_ISR() interrupt 1 using 2  
{
  TR0=0;
  TH0=0xff;  
  TL0=0x47;
  TR0=1;
  if(++uc1ms == 5)
{
uc1ms = 0;
        b1msInt=1;
if(++uc3ms==8)
  {
   uc3ms=0;
   b3msint=1;
    SendDataToDispDevice();
   }


}
}//void Timer0IntProg() interrupt 1 using 1

void Timer1_ISR() interrupt 3 using 3  
{
  TR1=0;
  TH1=0x00;  
  TL1=0x00;
  TR1=1;

}
void SendDataToDispDevice()
{
unsigned char n;
    //watchdog();
if(++ucDispOrder >= 2)  ucDispOrder = 0;

         if(ucDispOrder==0)
      {led1=0;
           led2=1;
       Nop();
            Nop();
  
   }
if(b3msint==1)
       {if(ucDispOrder==1)
       {led2=0;
            led1=1;
    Nop();
            Nop();
    }
}
       n = LedData[ucDispData[ucDispOrder]];
      P0=n;

  

} //void SendDataToDispDevice()

void main()
{

    init();
  beeping();
while(1)
  {
     TimeProg();
     Ir_process();
     display();
   
  }

}

void Ir_process()

{

  if(NewIRcode==1)
  {
    NewIRcode=0;
    customcode=(Irdcode>>16);   
                          Lcustomcode=customcode>>8;
    datacode=(unsigned char)(customcode&0x00ff);  
     
   
       Rdatacode=Lcustomcode;   

      if(~Rdatacode!=datacode)
  {  DataRight=0;
     Irdcode=0;
     datacode=Rdatacode=0;
   }

     else
{ DataRight=1;
   IR_E=1;
   mycode=datacode;}
     if(DataRight==1)  { bKeySound = 1;DataRight=0;  }
     
     }

   

}

void display()
  {
  /*  unsigned char a[2];
a[0] = mycode & 0x0f;
mycode = mycode >> 4;
a[1] = mycode & 0x0f;
ET0 = 0;
ucDispData[0] = a[0];
ucDispData[1] = a[1];
ET0 = 1;*/
if(IR_E==1)
{
ET0 = 0;
ucDispData[0] = mycode & 0x0f;
mycode = mycode >> 4;
ucDispData[1] = mycode & 0x0f;
    IR_E=0;
ET0 = 1;
}
}

void delay(unsigned char x)    //x*0.14MS
{
unsigned char a;
  while(x--)
{
  for (a = 0; a<13; a++) {;}
}
}


/**********************************************************/
void beeping()
{
  unsigned char i;
  
  for (i=0;i<100;i++)
   {
     delay(4);
     BEEP=!BEEP;                 
   }
  BEEP=1;
                    }





分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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