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

📄 9012_ir_jianma_program.c

📁 9012红外解码c程序 9012_IR_jianma_program 把接收到的数据解码!
💻 C
字号:


#include <reg51.h>
#include <intrins.h>

sbit LED=P1^7;

bit right


unsigned char txdata[3],bbb=0;


volatile unsigned char timeh,timel;
bit begin,start;
unsigned char whichbit;
unsigned char IRCodenum;
unsigned int inttemp;

unsigned char data IRCodedata[2];

unsigned char bdata IRCodetemp;
sbit IRCodetemp0=IRCodetemp^0;
sbit IRCodetemp1=IRCodetemp^1;
sbit IRCodetemp2=IRCodetemp^2;
sbit IRCodetemp3=IRCodetemp^3;
sbit IRCodetemp4=IRCodetemp^4;
sbit IRCodetemp5=IRCodetemp^5;
sbit IRCodetemp6=IRCodetemp^6;
sbit IRCodetemp7=IRCodetemp^7;

void main()
{
        TMOD=0x21;   /*T0 16位定时;T1常数自动装入8位*/
        TH0=0x0;
        TL0=0x0;    //T0 2ms
        TL1=0xe6;      /*12MHz-0e6 1200baud 12MHz-0xf3 4800baud*/
        TH1=0xe6;
        SCON=0x50;     //串行口方式1,允许接收
        PCON&=0x7f;
        IT1=1;       //外部1负跳变中断
        ET0=0;       //
        TR0=0;         //timer0不启动
        TR1=1;         //timer1启动
        ES=1;     /*tx/rx*///允许串行中断
        EX1=1;
        EA=1;          //开中断
        LED=0;
        start=1;
        while(1)
        {
                if(right==1)
                {
                    right=0;
                    txdata[0]=IRCodedata[0];
                    txdata[1]=IRCodedata[1];
                    LED=~LED;
                    SBUF=txdata[0];
                }
        }
}


void exint1() interrupt 2
{
    TR0=0;
    timeh=TH0;
    TH0=0;
    timel=TL0;
    TL0=0;
    TR0=1;    //timer0 启动
    inttemp=(int)timeh;
    inttemp=inttemp<<8;
    inttemp=inttemp+timel;
    LED=~LED;
    if(inttemp>3000)
    {
      begin=1;
      whichbit=9;
    }
    if(begin==1)
    {
         switch(whichbit)
         {
                      case 9:
                      whichbit=0;
                      break;
                      case 0:
                      if(inttemp>1500) IRCodetemp0=1;
                      else IRCodetemp0=0;
                      whichbit=1;
                      break;
                      case 1:
                      if(inttemp>1500) IRCodetemp1=1;
                      else IRCodetemp1=0;
                      whichbit=2;
                      break;
                      case 2:
                      if(inttemp>1500) IRCodetemp2=1;
                      else IRCodetemp2=0;
                      whichbit=3;
                      break;
                      case 3:
                      if(inttemp>1500) IRCodetemp3=1;
                      else IRCodetemp3=0;
                      whichbit=4;
                      break;
                      case 4:
                      if(inttemp>1500) IRCodetemp4=1;
                      else IRCodetemp4=0;
                      whichbit=5;
                      break;
                      case 5:
                      if(inttemp>1500) IRCodetemp5=1;
                      else IRCodetemp5=0;
                      whichbit=6;
                      break;
                      case 6:
                      if(inttemp>1500) IRCodetemp6=1;
                      else IRCodetemp6=0;
                      whichbit=7;
                      break;
                      case 7:
                      if(inttemp>1500) IRCodetemp7=1;
                      else IRCodetemp7=0;
                      start=1;
                      begin=0;
                      IRCodenum++;
                      IRCodedata[IRCodenum-1]=IRCodetemp;
                      if(IRCodenum==2)
                      {
                      IRCodenum=0;
                      right=1;
                      bbb=0;
                      }
                      break;
                   }
        }

}

 


serial () interrupt 4
{
  if(TI)
   {
        TI=0;
        bbb++;
        if(bbb<2)SBUF=txdata[bbb];
        else bbb=0;
   }
}

 
 

⌨️ 快捷键说明

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