找回密碼
         注冊(cè)會(huì)員
        搜索附件  

        ir_decode_test.rar

         

        紅外解碼求助!高手請(qǐng)進(jìn)!:
        程序如下:
        /**************************************************
        11.0592MHZ 晶振
        **************************************************/
        #include <reg52.h>
        #include "lcd_1602.h"
        #include "delay.h"
        #define uchar unsigned char
        #define uint unsigned int
        #define TEST_MODE 1 //1:測(cè)量引導(dǎo)碼長(zhǎng)度,2:顯示機(jī)器碼和鍵碼正反碼,3:顯示鍵值碼
        sbit ir = P3^3; //外部中斷1
        //定義一些燈,調(diào)試用。
        sbit led1 = P0^0;
        sbit led2 = P0^1;
        sbit led3 = P0^2;
        sbit led4 = P0^3;
        sbit led5 = P0^4;
        sbit led6 = P0^5;
        sbit led7 = P0^6;
        sbit led8 = P0^7;
        uint low_time,high_time; //測(cè)量高低電平時(shí)間
        uint common_code_time; //引導(dǎo)碼計(jì)數(shù)
        uint common_high_time; //引導(dǎo)碼高電平計(jì)數(shù)
        uint common_low_time; //引導(dǎo)碼低電平計(jì)數(shù)
        uchar new_key; //是否有新的接收
        uchar key_code; //鍵值的數(shù)值
        uchar a[4]; //存放接收到的4個(gè)自己數(shù)據(jù):用戶碼 + 用戶碼 + 鍵碼 + 鍵碼反碼
        void ired_init(void) //初始化
        {
        ir=1; //紅外端口寫1

        TMOD=0x10; //定時(shí)器1,工作方式1,16位定時(shí)器
        IT1=1; //INT1下降沿觸發(fā)
        EX1=1; //允許外部中斷1
        EX0 = 0;
        // ET1=1; //允許定時(shí)器1中斷
        EA=1; //開總中斷
        }
        void main(void)
        {
        uchar i;
        lcd_init();
        ired_init();
        lcd_1602_write_string_xy(1,1,"---IR DECODE---");
        while(1)
        {
        while(!new_key);//沒有新接收的鍵碼,在此等待。
        switch(TEST_MODE)
        {
        case 1:
        {
        //此段用于測(cè)量引導(dǎo)碼的高低電平,實(shí)際時(shí)間值等于數(shù)值*一個(gè)機(jī)器周期時(shí)長(zhǎng)。對(duì)于12M晶振來(lái)說(shuō)就是1us。
        lcd_1602_clr();
        lcd_1602_write_string_xy(1,1,"low_time:");
        lcd_1602_write_uint(common_low_time); //觀察低電平時(shí)長(zhǎng)
        lcd_1602_write_string_xy(2,1,"high_time:");
        lcd_1602_write_uint(common_high_time); //觀察高電平時(shí)長(zhǎng)
        break;
        }

        case 2:
        {
        //此段用于顯示兩個(gè)機(jī)器碼和數(shù)據(jù)碼的正反碼。
        lcd_1602_clr();
        lcd_1602_gotoxy(1,1);
        lcd_1602_write_string("a0,a1,a2,a3");
        lcd_1602_gotoxy(2,1);
        for(i = 0;i < 4;i ++)
        {
        lcd_1602_write_uchar(a);
        lcd_1602_write_data(',');
        }
        break;
        }
        case 3:
        {
        //用于顯示鍵碼
        lcd_1602_clr();
        lcd_1602_write_string_xy(1,1,"code_num:");
        lcd_1602_write_uchar(key_code);
        break;
        }
        default: lcd_1602_write_string_xy(2,1,"error");

        }

        new_key = 0;
        }
        }
        void int1_serv() interrupt 2
        {
        EA = 0;
        TH1 = 0; //給定時(shí)器裝初值,11.0592MHZ下機(jī)器周期是 12/11.0592 = 1.085us
        TL1 = 0;
        TR1 = 1;
        while(ir == 0);
        TR1 = 0;
        low_time = (TH1 << 8) + TL1;//保存低電平時(shí)間
        TH1 = 0;
        TL1 = 0;
        TR1 = 1;
        while(ir == 1);
        TR1 = 0;
        high_time = (TH1 << 8) + TL1;//保存低電平時(shí)間
        common_low_time = low_time;
        common_high_time = high_time;
        common_code_time = common_low_time + common_high_time;
        //P2 = common_high_time;
        //在此顯示一下引導(dǎo)碼的長(zhǎng)度。
        if((low_time > 7800) && (low_time < 8800) && (high_time > 3600) && (high_time < 4700)){ //判斷是否引導(dǎo)碼

        uchar i,j;
        uchar temp;
        for(i = 0;i < 4;i ++){ //接收四個(gè)字節(jié)
        for(j = 0;j < 8;j ++){ //每個(gè)字節(jié)8位
        temp >>= 1;
        TH1 = 0;
        TL1 = 0;
        TR1 = 1;
        while(ir == 0);
        TR1 = 0;
        low_time = (TH1 << 8) + TL1;
        TH1 = 0;
        TL1 = 0;
        TR1 = 1;
        while(ir == 1);
        TR1 = 0;
        high_time = (TH1 << 8) + TL1;
        if((high_time > 420) && (high_time < 620)){ //0
        temp &= 0x7f;
        }
        if((high_time > 1300) && (high_time < 1800)){ //1
        temp |= 0x80;
        }

        }
        a = temp;
        }
        if(a[2] == ~a[3]){
        P2 = a[3];
        key_code = a[2];
        new_key = 1;
        }
        }
        EA = 1;
        }

        主程序就這些,現(xiàn)在P2的led燈能正常顯示碼值,但主程序就是接收不到new_key信號(hào),進(jìn)不了1602顯示環(huán)節(jié),1602只顯示“---IR DECODE---”
        全局變量在中斷里改變后主程序不能接到嗎?請(qǐng)高手指點(diǎn)。


        QQ|手機(jī)版|MCU資訊論壇 ( 京ICP備18035221號(hào)-2 )|網(wǎng)站地圖

        GMT+8, 2025-5-3 22:18 , Processed in 0.039765 second(s), 8 queries , Redis On.

        Powered by Discuz! X3.5

        © 2001-2025 Discuz! Team.

        返回頂部
        91国内外精品自在线播放| 亚洲无码日韩精品第一页| 亚洲国产精品无码久久青草| 中日精品无码一本二本三本| 蜜国产精品jk白丝AV网站| 久久精品国产99国产电影网| 国产精品日韩欧美久久综合| 一二三四在线观看高清中文在线观看| 国产精品福利在线观看免费不卡 | 伊人久久精品无码av一区| 欲帝精品福利视频导航| 奇米影视7777久久精品| 久久精品国产网红主播| 久久精品国产亚洲一区二区| 四虎国产精品免费久久5151| 欧美日韩精品一区二区视频 | 国产精品莉莉欧美自在线线| 久久久不卡国产精品一区二区| 久久国产综合精品五月天| 亚洲精品无码久久久久久| 久久精品亚洲日本波多野结衣| 91久久精品国产免费直播| 2022麻豆福利午夜久久| 一区二区三区国产精品| 精品多毛少妇人妻AV免费久久| 亚洲精品亚洲人成人网| 久久99国内精品自在现线| 国产成人精品免高潮在线观看| 国产一区二区三区在线观看精品| 国模私拍视频在线| 日韩精品专区在线影院重磅| 国产乱人伦偷精品视频AAA| 国产精品熟女福利久久AV| 亚洲精品无码专区久久久| 国产成人精品视频一区二区不卡| 精品97国产免费人成视频| 久久国产乱子伦免费精品| 久久精品不卡| 国产精品国产精品国产专区不卡 | 精品久久香蕉国产线看观看亚洲| 亚洲精品久久久www|