標(biāo)題: 求大神幫忙講解一下這個(gè)紅外接收程序 [打印本頁]

作者: xjh272935444    時(shí)間: 2017-4-30 22:36
標(biāo)題: 求大神幫忙講解一下這個(gè)紅外接收程序
#include <reg52.H>
#include <intrins.h>

#define uchar unsigned char   
#define uint  unsigned int  

uchar code tab[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0X77,0X7c,0X39,0X5e,0X79,0X71,0x00};

sbit IR=P3^2;
sbit we1=P1^0;
sbit we2=P1^1;
sbit we3=P1^2;
sbit we4=P1^3;                 

uchar        N[4];                                 //識(shí)別碼,數(shù)據(jù)碼存放
uchar   X1,X2;

void XSQ(void);
void YS(uchar time);

/****************** 主函數(shù) *******************/
void main(void)
{
       
  X1=X2=0;


  IT0 = 1;
  EX0 = 1;
  EA  = 1;

  while(1)
  {
   XSQ();
  }
}

/**********************數(shù)碼管顯示函數(shù)************************/
void XSQ(void)
{
         we1=0;
     we2=0;
         we3=0;
         we4=0;
     we1=0;P0=tab[X1];we2=1;YS(1);       
     we2=0;P0=tab[X2];we1=1;YS(1);
}

/********************** 外部中斷函數(shù)************************/
void exint0() interrupt 0
{          
   uint cnt;
   uchar i;

   EX0 = 0;
   cnt = 0;       
       
   while(!IR)
   {
   cnt++;
    }                             //記錄引導(dǎo)碼時(shí)間
   if(cnt < 1000)
                   {EX0=1;return;}                   //9ms的計(jì)數(shù)值(12MHz:1000< cnt <1500)
          
   cnt = 0;
                            
   while(IR)
    {
       
   if(cnt++>400)
                   {EX0=1;return;}
                }        //防卡死,超時(shí)保護(hù)(12MHz: > 300)   
   if(cnt<200)
                   {EX0=1;return;}
                           //(12MHz不分頻: <260)            
          
   for(i=0; i<32; i++)                             //讀取32位位碼
       {
         cnt = 0;                                                                                                                                               
         while(!IR);                       
         while(IR)
                 if(cnt++ > 200)
                         {EX0=1;return;}  //超時(shí)保護(hù)(12MHz:>=200)
         N[i/8] >>= 1;
         if(cnt>60) N[i/8] |= 0x80;                //0和1的計(jì)數(shù)界線(12MHz:< 109)   
       }

         if(N[0] == ~N[1] && N[2] == ~N[3])            //校驗(yàn)識(shí)別碼,數(shù)據(jù)碼       
           {
          
                X1 = N[2]/16;
                X2 = N[2]%16;
           }

        EX0 = 1;
                         
}

/***************************************************************
延時(shí)程序
1ms×time       (晶振=12MHz)
***************************************************************/
void YS(uchar time)
{
     uchar i,j;
         for(i=0; i<time; i++)
     for(j=0; j<247; j++)_nop_();

}


作者: xjh272935444    時(shí)間: 2017-4-30 22:37
void exint0() interrupt 0
{         
   uint cnt;
   uchar i;

   EX0 = 0;
   cnt = 0;        
        
   while(!IR)
   {
   cnt++;
    }                             //記錄引導(dǎo)碼時(shí)間
   if(cnt < 1000)
                   {EX0=1;return;}                   //9ms的計(jì)數(shù)值(12MHz:1000< cnt <1500)
           
   cnt = 0;
                           
   while(IR)
    {
        
   if(cnt++>400)
                   {EX0=1;return;}
                }        //防卡死,超時(shí)保護(hù)(12MHz: > 300)   
   if(cnt<200)
                   {EX0=1;return;}
                           //(12MHz不分頻: <260)            
           
   for(i=0; i<32; i++)                             //讀取32位位碼
       {
         cnt = 0;                                                                                                                                                
         while(!IR);                       
         while(IR)
                 if(cnt++ > 200)
                         {EX0=1;return;}  //超時(shí)保護(hù)(12MHz:>=200)
         N[i/8] >>= 1;
         if(cnt>60) N[i/8] |= 0x80;                //0和1的計(jì)數(shù)界線(12MHz:< 109)   
       }

         if(N[0] == ~N[1] && N[2] == ~N[3])            //校驗(yàn)識(shí)別碼,數(shù)據(jù)碼        
           {
           
                X1 = N[2]/16;
                X2 = N[2]%16;
           }

        EX0 = 1;
                        
}
他的這個(gè)時(shí)間是怎么算的????求大神帶我飛。。!
作者: xjh272935444    時(shí)間: 2017-4-30 23:18
還有超時(shí)保護(hù)是什么意思???
作者: 卉心一笑    時(shí)間: 2017-4-30 23:38
建議你先看一下紅外通信原理,紅外接收數(shù)據(jù)解碼的方式跟編碼類似。時(shí)間的計(jì)算也是根據(jù)數(shù)據(jù)格式當(dāng)中的高低電平的時(shí)間來定的。我最近也在學(xué)習(xí)紅外通信這一塊,希望能對(duì)你有所幫助。相互學(xué)習(xí),共同進(jìn)步。

QQ圖片20170430233609.png (36.33 KB, 下載次數(shù): 62)

QQ圖片20170430233609.png

QQ圖片20170430233617.png (37.02 KB, 下載次數(shù): 58)

QQ圖片20170430233617.png

作者: xjh272935444    時(shí)間: 2017-5-1 14:52
這個(gè)我都知道,我想問這個(gè)程序中的38k是怎么算出來的
作者: xjh272935444    時(shí)間: 2017-5-1 14:53
不是,看錯(cuò)了,我想問cnt++的時(shí)間怎么算出來的




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