Infrared remote control microcontroller coding program plus detailed explanation

Publisher:会哭的蓝精灵Latest update time:2014-12-31 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
void IR_IN() interrupt 0 using 0 //Using 12MHz crystal
{
  unsigned char j,k,N=0;
     EX0 = 0; // Initialize, turn off external interrupt
  delay(15);
  if (IRIN==1) //no pulse arrives high level
     { EX0 =1; //Enable interrupt in default state, look for 9ms boot pulse
    return;
   }
                           //Confirm that the IR signal appears
  while (!IRIN) //Wait for IR to become high level and skip the 9ms leading low level signal.
    {delay(1);} //The MCU receiving level is completely opposite to the remote control level, delay(1) delay 0.14ms
 
 for (j=0;j<4;j++) //Collect four sets of data
 {
  for (k=0;k<8;k++) //Each set of data has 8 bits
  {
   while (IRIN) //Wait for IR to become low level and skip the 4.5ms leading high level signal.
     {delay(1);}
    while (!IRIN) //Wait for IR to become high level (0.56ms)
     {delay(1);}
     while (IRIN) //Calculate the duration of IR high level
      {
    delay(1);
    N++;          
    if (N>=14) //Greater than 1.685ms high level length, in order to ensure reliability N=14
  { EX0=1; //(2.25/0.14=16,1.685/0.14=12,0.565/0.14=4)
  return;} //0.14ms count is too long, automatically exit, re-judge.
      } //High level counting completed               
     IRCOM[j]=IRCOM[j] >> 1; //Fill the highest bit of data with "0"
     if (N>=6) {IRCOM[j] = IRCOM[j] | 0x80;} //High level length greater than 0.565ms, N=6, 7, 8 (1.685/2) are all OK, judged as "1", the highest bit of the data is filled with "1"
     N=0;
  }//end for k
 }//end for j
  
   if (IRCOM[2]!=~IRCOM[3]) The data code is opposite to the data inverse code, continue to execute, otherwise, the data is wrong. Return and re-judge.
   { EX0=1;
     return; }
 
   IRCOM[5]=IRCOM[2] & 0x0F; //Get the lower four bits of the key code
   IRCOM[6]=IRCOM[2] >> 4; // Shift right 4 times, the upper four bits become the lower four bits
 
   if(IRCOM[5]>9)
    { IRCOM[5]=IRCOM[5]+0x37;} //Convert to the corresponding ASCII code and send to 1602 for display.
   else
   IRCOM[5]=IRCOM[5]+0x30;
 
   if(IRCOM[6]>9)
    { IRCOM[6]=IRCOM[6]+0x37;}
   else
   IRCOM[6]=IRCOM[6]+0x30;
 
     lcd_pos(0x4b);            
     lcd_wdat(IRCOM[6]); //First digit display
     lcd_pos(0x4c);              
     lcd_wdat(IRCOM[5]); //The second digit is displayed
 
     beep();
     EX0 = 1; //Open interrupt and continue judging
}
Reference address:Infrared remote control microcontroller coding program plus detailed explanation

Previous article:Microcontroller as infrared remote control decoder
Next article:Electronic clock based on single chip microcomputer, DS1302 and DS1602

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号