標(biāo)題: 單片機(jī)開(kāi)發(fā)紅外遙控三色燈—紅外接收部分程序 [打印本頁(yè)]

作者: 李鑫都    時(shí)間: 2021-8-16 15:14
標(biāo)題: 單片機(jī)開(kāi)發(fā)紅外遙控三色燈—紅外接收部分程序
void interrupt Timer0_Isr()//200us
{
        TMR0=0;                                                        //初值
        T0IF=0;                                                        //溢出中斷標(biāo)志位清零
        if(IR_R)
        {               
                F_H_first = 1;
                R_H_count++;                                                                //高電平計(jì)時(shí)
                if(R_H_count > 100)                                                               
                {
                        R_H_count = 0;
                        F_L_start = 0;
                        F_H_start = 0;
                        F_rec_ok = 0;
                        R_rec_DATE = 0;
                        R_rec_countL = 0;
                        F_repeat_ok = 0;
                }
                if(F_L_first)
                {
                        F_L_first = 0;
                        if(F_H_start == 0)
                        {
                                if((R_L_count > 40)&&(R_L_count < 50))                                //低電平時(shí)間為9ms左右
                                {
                                        F_L_start = 1;                                                                        //低電平引導(dǎo)碼
                                }
                        }
                        R_L_count = 0;
                }
        }
        else
        {        
                F_L_first = 1;
                R_L_count++;                                                                //低電平計(jì)時(shí)
                if(R_L_count > 100)                                                        //計(jì)時(shí)大于50ms,干擾,清除所有標(biāo)志,不讀        
                {
                        R_L_count = 0;
                        F_L_start = 0;
                        F_H_start = 0;
                        F_rec_ok = 0;
                        R_rec_DATE = 0;
                        R_rec_countL = 0;
                        F_repeat_ok = 0;
                }
                if(F_H_first)        
                {
                        F_H_first = 0;
                        if(F_L_start)
                        {
                                if(F_H_start)
                                {
                                        R_rec_countL++;                                //每變換一次電平計(jì)次一次
                                        R_rec_DATE<<=1;                        //從最高位開(kāi)始讀取
                                        if(R_rec_countL > 16)                                                //從第17位開(kāi)始讀取數(shù)據(jù)
                                        {
                                                if((R_H_count > 6)&&(R_H_count < 11))
                                                {
                                                        R_rec_DATE |= 0x01;                                //若高電平持續(xù)時(shí)間為1.72ms左右,讀為1,否則0
                                                }
                                                if(R_rec_countL >= 24)                                        //24位讀完
                                                {
                                                        R_rec_countL = 0;
                                                        R_real_date = R_rec_DATE;
                                                        F_L_start = 0;
                                                        F_H_start = 0;
                                                        F_rec_ok = 1;                //數(shù)據(jù)讀取完畢
                                                        R_rec_DATE = 0;
                                                }
                                        }
                                }
                                else
                                {
                                        if((R_H_count > 10)&&(R_H_count < 14))                        //2.4ms左右
                                        {
                                                R_repeat_count++;
                                                if(R_repeat_count > 1)
                                                {
                                                        F_repeat_ok = 1;        //重復(fù)碼標(biāo)志
                                                }                                                        
                                        }
                                        else if((R_H_count > 20)&&(R_H_count < 25))                        //高電平時(shí)間4.5ms左右
                                        {
                                                F_H_start = 1;                                                                                        //視為高電平引導(dǎo)碼
                                                F_repeat_ok = 0;
                                                R_repeat_count = 0;
                                        }
                                        else
                                        {
                                                F_L_start = 0;
                                                F_repeat_ok = 0;
                                                R_repeat_count = 0;
                                        }        
                                }
                        }
                        R_H_count = 0;
                }
        }
        if(PBIF)
        {
                PBIF = 0;                                                        //清中斷標(biāo)志
                PORTB=PORTB;
        }
}


作者: zctwss321    時(shí)間: 2021-8-20 17:43
為什么是部分???  而不是全部?  小氣了




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1