找回密碼
         注冊(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.

        返回頂部
        久久香蕉超碰97国产精品| 国产精品永久免费视频| 蜜臀av无码人妻精品| 九九线精品视频在线观看| 亚洲国产天堂久久精品网| 久久精品国产清高在天天线| 久久国产精品99久久久久久老狼| 国产精品亚洲欧美大片在线观看 | 久久精品中文字幕久久| 国产精品无码素人福利不卡| 亚洲一级Av无码毛片久久精品| 人妻少妇精品中文字幕AV| 6一12呦女精品| 精品国偷自产在线视频| 一二三四视频社区在线播放中国| 国产精品多p对白交换绿帽| 国产香蕉国产精品偷在线 | 国产成人精品免费视频动漫| 国产99久久久国产精品~~牛| 伊人精品视频在线| 国产精品亚洲精品观看不卡| 久久人人爽人人精品视频| 久久国产亚洲精品无码| 国产午夜亚洲精品理论片不卡| 日韩精品区一区二区三VR| 国产成人精品cao在线| 91视频-88av| 高清日韩精品一区二区三区| 无码人妻精品一区二区三区夜夜嗨 | 亚洲精品无码久久久久| 91大神精品全国在线观看| 自拍偷自拍亚洲精品第1页| 国产午夜精品理论片久久影视| 亚洲欧洲精品成人久久奇米网| 国产精品你懂的| 日本免费新一区视频| 99国内精品久久久久久久| 亚洲av永久无码精品国产精品| 国产91精品黄网在线观看| 久久精品人人槡人妻人人玩AV | 亚洲AV永久无码精品|