欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3550|回復: 0
打印 上一主題 下一主題
收起左側

單片機紅外二極管編碼發射程序+原理圖

[復制鏈接]
跳轉到指定樓層
樓主
這是一個紅外發碼解碼的原理,利用一個普通的紅外發射管,利用一個IO口,發射38KHz的載波與按鍵。這個原理圖中沒有按鍵,所以程序中就發了固定的紅外碼值,如果需要加入按鍵的話直接加入按鍵掃描的程序即可。本程序是的開發語言是mini C(為了適用特別的編譯器),基本上是和C語言一樣的,只是個別關鍵字不一樣而已。

電路原理圖如下:


單片機源程序如下:

//發射源碼
#include        "extern.h"

.RAMADR        0


WORD        zero;
WORD    count;
WORD        set_count;
WORD        cnt0;

BYTE    FLAG_1;

//WORD           cnt1;
//BYTE           cnt2;
//BYTE           cnt3;
//BYTE        irdata;
BYTE        ircode;


//.RAMADR        SYSTEM
BIT        ir                                :        PA.3;


BIT        ir_flag                 :        FLAG_1.0;


void  INIT(void)
{
     PA=0XFF;                       //IO
     PAC=0B_1111_1111;              //輸入設置 1為輸出                         PA4輸入
     PAPH=0X00;                                                //無上拉
     $ PADIER  0B_0000_0000;        //使能數字輸入及喚醒功能,0數字,1模擬   
//  disgint ;
         inten.2=1;                     //tm16溢出中斷
         intrq=0;

         t16m=0B_001_00_000;            //SYSCLK_4m,1分頻,8位中斷,1/(4M/1) = 0.25us
         integs=0B_0000_0000;

         WORD    t_count=215;                          
         stt16   t_count;                                        //tm16置初值,定時0.25*(256-204)=13us

         engint;                                                //使能中斷

}

void  delay_ms(void)//24ms
{
     while(1)
     {
             cnt0++;
                 if(cnt0>=8000)
                  {
                        cnt0=0;
                break;
                  }
    }      
}

void delay_s(void)
{
        BYTE i = 2;//2
        do
        {
                delay_ms();
        }while(i--);
}

void ir_sendbyte(void)
{
        BYTE i = 8;
        do
        {
                i--;
                set_count = 43;//發送560us高電平
                ir_flag = 1;//啟動紅外發射
                count = 0;
                set1        t16m.5;//開啟定時器
                while(1)
                {
                        if(count > set_count) break;
                }
                set0        t16m.5;//關閉定時器

               if(ircode.0) set_count = 130;//判斷紅外編碼最低位,若為1則為1.69ms低電平

                else set_count = 43;//否則為560us低電平
                ir_flag = 0;//低電平不發射
                count = 0;
                set1        t16m.5;
                while(1)
                {
                        if(count > set_count) break;
                }
                set0        t16m.5;
                ircode = ircode>>1;
        }while(i);
}

void ir_send1(void)
{
        set_count = 782;//692發送編碼中的引導碼(9ms+4.5ms)
        ir_flag = 1;//啟動紅外
        count = 0;
        set1        t16m.5;//開啟定時器
        while(1)
        {
                if(count > set_count) break;
        }
        set0        t16m.5;//關閉定時器
        set_count = 346;//發送編碼中的4.5ms低電平
        ir_flag = 0;
        count = 0;
        set1        t16m.5;//開啟定時器
        while(1)
        {
                if(count > set_count) break;
        }
        set0        t16m.5;//關閉定時器

ircode = 0x00;//用戶碼前8位
        ir_sendbyte();
        ircode = 0xff;//用戶碼后8位
        ir_sendbyte();
        ircode = 0x56;//8位數據碼0x56 測試0x45 反0xba
        ir_sendbyte();
        ircode = 0xa9;//數據碼反碼0xa9
        ir_sendbyte();
        set_count = 43;//發送編碼中的560us高電平
        ir_flag = 1;
        count = 0;
        set1        t16m.5;//開啟定時器

while(1)
        {
                if(count > set_count) break;
        }
        set0        t16m.5;//關閉定時器
        ir = 1;

        delay_ms();//23ms
        
        set_count = 782;//發送引導碼
        ir_flag = 1;
        count = 0;
        set1        t16m.5;//開啟定時器
        while(1)
        {
                if(count > set_count) break;
        }

set0        t16m.5;
        set_count = 346;//發送編碼中的4.5ms低電平
        ir_flag = 0;
        count = 0;
        set1        t16m.5;//開啟定時器
        while(1)
        {
                if(count > set_count) break;
        }
        set0        t16m.5;
        set_count = 43;
        ir_flag = 1;
        count = 0;
        set1        t16m.5;//開啟定時器
        while(1)
        {
                if(count > set_count) break;
        }
        set0        t16m.5;
        ir = 1;
}

void ir_send2(void)
{
        set_count = 782;//692發送編碼中的引導碼(9ms+4.5ms)
        ir_flag = 1;//啟動紅外
        count = 0;
        set1        t16m.5;//開啟定時器
        while(1)
        {
                if(count > set_count) break;
        }
        set0        t16m.5;//關閉定時器
        set_count = 346;//發送編碼中的4.5ms低電平
        ir_flag = 0;
        count = 0;
        set1        t16m.5;//開啟定時器
        while(1)
        {
                if(count > set_count) break;
        }
        set0        t16m.5;//關閉定時器

ircode = 0x00;//用戶碼前8位
        ir_sendbyte();
        ircode = 0xff;//用戶碼后8位
        ir_sendbyte();
        ircode = 0x34;//8位數據碼0x34 測試0x47 反0xb8
        ir_sendbyte();
        ircode = 0xcb;//數據碼反碼0xcb
        ir_sendbyte();
        set_count = 43;//發送編碼中的560us高電平
        ir_flag = 1;
        count = 0;
        set1        t16m.5;//開啟定時器

        while(1)
        {
                if(count > set_count) break;
        }
        set0        t16m.5;//關閉定時器
        ir = 1;

delay_ms();//23ms
        
        set_count = 782;//發送引導碼
        ir_flag = 1;
        count = 0;
        set1        t16m.5;//開啟定時器
        while(1)
        {
                if(count > set_count) break;
        }
        set0        t16m.5;
        set_count = 346;//發送編碼中的4.5ms低電平
        ir_flag = 0;
        count = 0;
        set1        t16m.5;//開啟定時器
        while(1)
        {
                if(count > set_count) break;
        }

set0        t16m.5;
        set_count = 43;
        ir_flag = 1;
        count = 0;
        set1        t16m.5;//開啟定時器
        while(1)
        {
                if(count > set_count) break;
        }
        set0        t16m.5;
        ir = 1;
}

void        FPPA0 (void)
{
        .ADJUST_IC        SYSCLK=IHRC/4                //        SYSCLK=IHRC/2

        //        Insert Initial Code
         //清除RAM
        Zero = _SYS(RAM_SIZE)-1;
        a = 0;
        do
        {
                *Zero = a;
        }while(--Zero$0);

        count = 0;
        ir_flag = 0;
        INIT();
        while (1)
        {
               
                ir_send1();
                delay_s();
                ir_send2();
                delay_s();
//                wdreset;
        }
}


評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表