新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 一個紅外線發(fā)射+解碼程序+仿真文件

一個紅外線發(fā)射+解碼程序+仿真文件

作者: 時間:2016-11-29 來源:網(wǎng)絡(luò) 收藏
/*┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈函數(shù):遙控短按處理┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈*/void KZ0(){switch(NEC[2]) {case 0x12: P10 = !P10; break;case 0x05: break;case 0x1E: break;case 0x55: break;case 0x01: break;case 0x1B: break;case 0x03: break;case 0x6B: break;case 0x07: break;case 0x08: break;case 0x09: break;case 0x68: break;case 0x22: break;case 0xE6: break;case 0x33: break;case 0xE2: break;default:break;}}/*┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈函數(shù):遙控長按處理┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈*/void KZ1(){switch(NEC[2]) {case 0x12: P14 = !P14; break;case 0x05: break;case 0x1E: break;case 0x55: break;case 0x01: break;case 0x1B: break;case 0x03: break;case 0x6B: break;case 0x07: break;case 0x08: break;case 0x09: break;case 0x68: break;case 0x22: break;case 0xE6: break;case 0x33: break;case 0xE2: break;default:break;}}/*********************數(shù)碼管掃描*************************/void XS(void){ if(++Xn > 7)Xn=0;switch(Xn) {case 0: WX8=1; NOP; //屏蔽上個位顯SE=tab[X1]; //送段碼WX1=0; //開位顯break;case 1: WX1=1; NOP; SE=tab[X2]; WX2=0; break;case 2: WX2=1; NOP; SE=tab[X3]; WX3=0; break; case 3: WX3=1; NOP; SE=tab[X4]; WX4=0; break;case 4: WX4=1; NOP; SE=tab[16]; WX5=0; break;case 5: WX5=1; NOP; SE=tab[16]; WX6=0; break;case 6: WX6=1; NOP; SE=tab[X5]; WX7=0; break;case 7: WX7=1; NOP; SE=tab[X6]; WX8=0; break; default:break; }} /********************** 定時器0中斷函數(shù)************************/void time0(void) interrupt 1{ IR_NEC(); XS(); }

接收源程序+仿真
點擊此處下載http://www.51hei.com/f/hong1.rar

本文引用地址:http://m.butianyuan.cn/article/201611/323430.htm

遙控器源程序
點擊此處下載http://www.51hei.com/f/hong2.rar

/***************************************************************作品:紅外線遙控發(fā)射(NEC編碼)單片機:STC89C52RC晶振:12M***************************************************************///// 發(fā)射引腳(接PNP三極管b極)// PNP三極管e極接2Ω電阻,c極接紅外發(fā)射管#include #include "INCMY_SET.h"#include "INCLCD1602_6IO.h"  sbit  IR  = P3^6;                  //發(fā)射引腳(接PNP三極管基極)#define  USER_H   P2              //用戶碼高8位#define  USER_L   P0              //用戶碼低8位uint8c tab[16] = {                  //操作碼0x12,0x05,0x1e,0x55,0x01,0x1b,0x03,0x6b,0x07,0x08,0x09,0x68,0x22,0xE6,0x33,0xe2};#define m9    (65536-9000)           //9mS#define m4_5  (65536-4500)           //4.5mS#define m1_6  (65536-1650)           //1.65mS#define m_56  (65536-560)           //0.56mS#define m40   (65536-40000)       //40mS#define m56   (65536-56000)       //56mS#define m2_25 (65536-2250)        //2.25mSvoid  SanZhuan();uint8 KEY(void);void  ZZ(uint8 x);                  //NEC編碼發(fā)送程序void  Z0(uint8 temp);                  //單幀(8位數(shù)據(jù))發(fā)送程序void  TT0(bit BT,uint16 x);          //38KHz載波發(fā)射 + 延時程序/*┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈函數(shù):主程序┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈*/void main(void){ TMOD = 0x01;         //T0 16位工作方式IR=1;                  //發(fā)射端口常態(tài)為高電平L1602_Init(); L1602_clr();L1602_xy(0,0);L1602_ZIFUC("UserCode :0x"); L1602_xy(0,1);L1602_ZIFUC("Opcode   :0x");while(1) {           L1602_xy(12,0);L1602_JZ(USER_H,16,1);L1602_JZ(USER_L,16,1);SanZhuan();}}/*┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈函數(shù):4×4矩陣鍵盤【 線翻轉(zhuǎn)法鍵值表 】                    P1.0  P1.1  P1.2  P1.3  P1.4  P1.5  P1.6  P1.7 │     │    │    │    │    │    │    │    │     │    │    └──7e    be    de   ee      │     │    └─────7d    bd    dd   ed      │     └────────7b    bb    db   eb      └─────────── 77    b7    d7   e7    ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈*/uint8 KEY(void){uint8 Key = 0;P1 = 0xf0;           //鍵盤初始:行值=0,列值=1NOP;                 //緩沖,待IO端口電位穩(wěn)定Key = P1&0xf0;       //得到行標(biāo)志P1  = 0x0f;          //翻轉(zhuǎn)鍵盤接口輸出NOP;Key |= (P1&0x0f);    //列標(biāo)志 + 行標(biāo)志return Key;          //返回鍵值}/*┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈函數(shù):散轉(zhuǎn)程序┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈*/void SanZhuan(){uint8 v;v = KEY();                           //鍵盤檢測switch(v){case 0x7e:ZZ(tab[0]);break;                case 0xbe:ZZ(tab[1]);break;                case 0xde:ZZ(tab[2]);break;                case 0xee:ZZ(tab[3]);break;                case 0x7d:ZZ(tab[4]);break;                case 0xbd:ZZ(tab[5]);break;                case 0xdd:ZZ(tab[6]);break;                case 0xed:ZZ(tab[7]);break;case 0x7b:ZZ(tab[8]);break;                case 0xbb:ZZ(tab[9]);break;                case 0xdb:ZZ(tab[10]);break;                case 0xeb:ZZ(tab[11]);break;case 0x77:ZZ(tab[12]);break;                case 0xb7:ZZ(tab[13]);break;                case 0xd7:ZZ(tab[14]);break;                case 0xe7:ZZ(tab[15]);break;                                default:break;}v=0;}/*┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈函數(shù):NEC編碼發(fā)送程序┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈*/void ZZ(uint8 Value){ L1602_xy(12,1);L1602_JZ(Value,16,1);    //更新顯示TT0(1,m9);             //高電平9mSTT0(0,m4_5);             //低電平4.5mS/*┈ 發(fā)送4幀數(shù)據(jù)┈*/Z0(USER_H);             //用戶碼高8位Z0(USER_L);             //用戶碼低8位Z0(Value);             //操作碼Z0(~Value);             //操作碼反碼/*┈┈ 結(jié)束碼 ┈┈*/TT0(1,m_56);TT0(0,m40);/*┈┈ 重復(fù)碼 ┈┈*/while(KEY() != 0xFF){TT0(1,m9);TT0(0,m2_25);TT0(1,m_56);TT0(0,m40);TT0(0,m56);                                  }                   }/*┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈函數(shù):單幀(8位數(shù)據(jù))發(fā)送程序入口:temp┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈*/void Z0(uint8 temp){ uint8 v;for(v=0;v<8;v++)  {     TT0(1,m_56);                  //高電平0.65mS         if(temp&0x01) TT0(0,m1_6);  //發(fā)送最低位else          TT0(0,m_56);     temp >>= 1;                 //右移一位 }    }/*┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈函數(shù):38KHz載波發(fā)射 + 延時程序入口:(是否發(fā)射載波,延時約 x (uS))┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈*/void TT0(bit BT,uint16 x){TH0 = x>>8;                  //輸入定時值TL0 = x;TF0=0;                        //溢出標(biāo)志位清0TR0=1;                        //啟動定時器0if(BT == 0) while(!TF0);        //BT=0時,不發(fā)射38KHz載波只延時;else while(1)                //BT=1時,發(fā)射38KHz脈沖+延時;38KHz載波(低電平)占空比5:26{IR = 0;if(TF0)break;if(TF0)break;IR = 1;if(TF0)break;if(TF0)break;if(TF0)break;if(TF0)break;if(TF0)break;if(TF0)break;if(TF0)break;if(TF0)break;if(TF0)break;if(TF0)break;}TR0=0;          //關(guān)閉定時器0IR =1;          //載波停止后,發(fā)射端口常態(tài)為高}

上一頁 1 2 下一頁

評論


技術(shù)專區(qū)

關(guān)閉