久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標題: AT89C2051紅外遙控解碼(C語言)程序文件 Main.C IR.h [打印本頁]

作者: xiaogu    時間: 2014-12-13 22:42
標題: AT89C2051紅外遙控解碼(C語言)程序文件 Main.C IR.h
#include <reg52.h>
#include "IR.h"

sbit led = P3^7;

void main(void){   
    cpu_init();
led=1;   
    while(1){
  P1=~IRdata;
  isirinit=1;
  switch (IRdata){
   case 0x45:{     //在這里添加代碼
     led=~led;
    break;
   }
   default:{
    isirinit=0;
    break;
   }
  }
  if (isirinit==1) IRdata=0xff;
}
}   


作者: xiaogu    時間: 2014-12-13 22:42
IR.h 文件:

#include <reg52.h>
#define msec_12p5  0x2d00  //Fosc=11.0592MHz   
#define msec_15  0x3600   
#define msec_9  0x2066   
#define msec_2p5  0x900    //#define msec_9  0x1066
#define msec_0p9  0x33d   
#define msec_1p68  0x610

typedef enum{   
             IR_idle,   
             IR_waitstart,            
             IR_getaddr,            
             IR_getaddrinv,            
             IR_getdata,            
             IR_getdatainv            
            }_IRstate;                  
  
_IRstate IRstate = IR_idle;   
  
unsigned char IRaddr=0xff;   
unsigned char _IRaddr=0xff;   
unsigned char IRdata=0xff;   
unsigned char _IRdata=0xff;   
unsigned char IR_repeat=0;   
unsigned char IR_ready=0;   
unsigned char  IR_poweron=0;

bit isirinit=0;  //是否刷新,即接到正確碼
  
//bit ir_done=0;   
// time constants   
unsigned int IRtimer=0; // IR timeout   

//cpu初始化   
void cpu_init(void){     
    TMOD=0X11; // T0 and T1 十六位定時                  
    TH0=0xee;  //fosc=11.0592M,timer=5ms   
    TL0=0x00;   
    TR0=1; // run timer 0;   
    TF0=0;   
  
    ET0=1;  // enable tmr 0 overflow interrupt   
    IT0=1; // int0 edge sensitive   
    EX0=1; //  enable "int0"   
    EA=1;   // global interupt enable   
}
void tmrint() interrupt 1{ //T0中斷      
    TH0=0xee;   
    TL0=0x00;   
    if (IRtimer)     //IR接收超時   
        --IRtimer; //   
    else  
    {   
        IRstate=IR_idle;   
//        IR_poweron=0;   
    }   
}     
//void IRint() interrupt 0(void)   
  
//When the IR receive pin goes low and interrupt is generated   
// IR is collected by starting timer 2 in the first falling edge of the in  
// then on every other falling edge, the timer value is saved and the timer restarted .     
// the captured time is then used to get the IR data   
// a "start of data" is 13.5Msec,a "1" is 2.25Msec,a "0" is 1.12 msec and a "repeat" is 11.25msec.   
// the counter increments at 1.085 Usec   
// I allow a fairly large tolerance to time jitter but there are no false triggers seen.   
  
void IRint() interrupt 0{   
    static unsigned char bits;   
    unsigned short time;

    switch(IRstate)   
    {   
        case IR_idle:   
            TL1=0;   
            TH1=0;   
            TR1=1;   
            IRstate=IR_waitstart;   
            IRtimer=26;   
            break;   
        case IR_waitstart: //P2_4=!P2_4;   
            TR1=0;   
            time=TH1;   
            time =(time <<8)+TL1;;   
            TL1=0;   
            TH1=0;   
            TR1=1;   
            if ((time > msec_12p5)&&(time < msec_15)) // greater than 12.5Msec & less than 15 msec = start code   
            {      
                IRaddr=0;   
                _IRaddr=0;   
                IRdata=0;   
                _IRdata=0;   
                bits=1;   
                IRstate=IR_getaddr;   
            }   
            else if ((time > msec_9)&&(time <  msec_12p5))// less than 12.5Msec  and greater than 9 msec =Repeat code   
            {        
                IR_repeat=2;   
                IRstate=IR_idle;   
            }   
            else   
            {           // to short, bad data just go to idle   
                IRstate=IR_idle;                  
            }                  
            break;   
        case IR_getaddr:    // P2_4=!P2_4;   
            TR1=0;   
            time=TH1;   
            time =(time <<8)+TL1;;   
            TL1=0;   
            TH1=0;   
            TR1=1;   
            if ((time>msec_2p5)||(time<msec_0p9))// if  > 2.5msec or shorter than .9Msec bad data , go to idle   
            {      
                IRstate=IR_idle;   
                break;   
            }   
            if (time>msec_1p68)// greater than 1.68Msec is a 1   
            {         
                IRaddr|= bits;   
            }   
            bits=bits<<1;   
            if (!bits)   
            {   
                IRstate=IR_getaddrinv;                  
                bits=1;   
            }   
            break;                 
        case IR_getaddrinv:  //P2_4=!P2_4;   
            TR1=0;   
            time=TH1;   
            time =(time <<8)+TL1;;   
            TL1=0;   
            TH1=0;   
            TR1=1;   
            if ((time>msec_2p5)||(time<msec_0p9))// if  > 2.5msec or shorter than .9Msec bad data , go to idle   
            {      
                IRstate=IR_idle;   
                break;   
            }   
            if (time>msec_1p68)// greater than 1.68Msec is a 1   
            {        
                _IRaddr|= bits;   
            }   
            bits=bits<<1;   
            if (!bits)   
            {   
                IRstate=IR_getdata;;                  
                bits=1;   
            }   
            break;                 
        case IR_getdata:   
            TR1=0;   
            time=TH1;   
            time =(time <<8)+TL1;;   
            TL1=0;   
            TH1=0;   
            TR1=1;   
            if ((time>msec_2p5)||(time<msec_0p9))// if  > 2.5msec or shorter than .9Msec bad data , go to idle   
            {      
                IRstate=IR_idle;   
                break;   
            }   
            if (time>msec_1p68)// greater than 1.68Msec is a 1   
            {         
                IRdata|= bits;   
            }   
            bits=bits<<1;   
            if (!bits)   
            {   
                IRstate=IR_getdatainv;                  
                bits=1;   
            }   
            break;                 
        case IR_getdatainv:   
            TR1=0;   
            time=TH1;   
            time =(time <<8)+TL1;;   
            TL1=0;   
            TH1=0;   
            TR1=1;   
            if ((time>msec_2p5)||(time<msec_0p9)) // if  > 2.5msec or shorter than .9Msec bad data , go to idle   
            {      
                IRstate=IR_idle;   
                break;   
            }   
            if (time>msec_1p68)// greater than 1.68Msec is a 1   
            {        
                _IRdata|= bits;   
            }   
            bits=bits<<1;   
            if (!bits)         // we have it all , now we make sure it is a NEC code from the CHS IR transmitter   
            {                   // make sure address,~address are correct , data ,~data are correct and address is 0.   
                IR_ready=((IRaddr^_IRaddr)==0xff)&&((IRdata^_IRdata)==0xff)&&(IRaddr==0);   
                if(IR_ready)   
                {   
                    IRstate=IR_idle;   
                }      
            }   
            break;                 
        default:   
            IRstate=IR_idle;   
            break;   
    }   
}   

作者: 51hei電控2112312    時間: 2014-12-21 04:35
很好,正需要
作者: bhjyqjs    時間: 2015-6-2 10:03
真不錯的東東,頂一個




歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 天天搞天天操 | 日韩欧美国产一区二区 | a免费视频 | 爱高潮www亚洲精品 中文字幕免费视频 | 毛片a级| 成人久久18免费网站 | 天天影视综合 | 国产精品一区二区不卡 | 亚洲高清在线 | 黄色在线免费观看视频网站 | 日本精品一区二区在线观看 | 国外成人在线视频网站 | 日日摸天天添天天添破 | 国产最新精品视频 | 一区二区三区中文字幕 | 3p视频在线观看 | 自拍偷拍精品 | 一二区视频| 亚洲精品一区二区 | 羞羞视频网站免费观看 | 人人插人人 | 91久久夜色 | 久久久久无码国产精品一区 | 日韩精品一区二区三区中文在线 | 精品国产18久久久久久二百 | 中文字幕一区二区在线观看 | 成人国产免费视频 | 91网视频 | 欧洲免费视频 | 日韩欧美三级电影 | 91视频免费观看 | 亚洲天堂精品一区 | 亚洲精品视频免费 | 国产情侣在线看 | 日韩精品久久久 | av永久| 在线观看中文字幕av | 亚洲电影免费 | 伊人久久精品一区二区三区 | 欧美精品91爱爱 | 久久99视频这里只有精品 |