Infrared remote control system principle with 51 single-chip microcomputer software decoding program

Source: Internet
Author: User
Tags 0xc0 clear screen first row

The infrared receiver Head model has many HS0038 VS838 and other functions are roughly the same, but the PIN package is different.

Infrared receiver has several unified encoding method, which encoding method depends on the chip used by the remote control, the receiving head received is the same.

TV Remote control using a dedicated integrated transmitter chip to achieve remote control code launch, such as Toshiba TC9012, Philips AA3010T, etc., usually color TV remote signal transmission, is the control command and system code (composed of 0 and 1) corresponding to a key, modulated on the 38KHz carrier, and then by amplification , and drive the infrared emitter to send out the signal. The remote control chip of different companies, sampling the remote control code format is not the same, more common there are two, a NEC standard, one is the Philips standard.

NEC Standard: The frequency of the remote control carrier is 38KHz (duty 1:3) When a key is pressed, the system first launches a full full code, if the key is more than 108ms is still not released, the next launch code (bursts code) will be the starting code (9MS) and the End Code (2.5MS) composition.
A full code = boot code + user code + user code + data code + data code + data anti-code.

Among them, the boot code high level 9ms, low level 4.5ms, the system code 8 bits, data code 8 bits, a total of 32 bits, of which the first 16 bits for the user identification code, can distinguish between different infrared remote control devices, to prevent different types of remote control codes interfere with each other. The latter 16 bits are 8-bit opcode and 8-bit Operation counter code, used to check whether the data received accurately. The receiver is judged based on the data code to perform the above actions.

The bursts code is the code that is sent when the key is pressed continuously. It informs the receiving end. A key is being pressed continuously.

Transmission Code representation under NEC Standard
TX Data 0 O'Clock is indicated by "0.56ms high + 0.565ms low = 1.125ms";
Data 1 is indicated with "high-level 0.56ms + 1.69ms = 2.25ms".
TX TX Signal:

It is important to note that when the integrated receiver head receives the 38KHZ IR signal, the output output is low, otherwise the high level. So the waveform and transmit waveform of the integrated receiver head output are reversed.

Philips Standard:
Carrier frequency 38KHz: No cylinder, click the button, the control code between 1 and 0 switch, if the constant key, the control code is unchanged.
A full code = start code ' 11 ' + control code + user code + user code
Data 0 is indicated by "low level 1.778ms + high level 1.778ms";
Data 1 is expressed as "high-level 1.778ms + low-level 1.778ms".
Continuous code repetition delay of 114ms.

The so-called decoding is a process of distinguishing the pulse width. The 0 and 1 of the red Dwarf signal are differentiated by the duration of the pulses,

My remote control uses the NEC standard WD6122 chip, the remote control code is as follows:

The following is a program that I received using 1602 to display the infrared receiver header:
① This is a function of the 1602 operation

------------------------------------------------*/#include "1602.h" #include "delay.h" #define CHECK_BUSY sbit RS = P2   ^4;
Define port Sbit RW = p2^5;

Sbit EN = p2^6; #define RS_CLR rs=0 #define RS_SET rs=1 #define RW_CLR rw=0 #define RW_SET rw=1 #define EN_CLR en=0 #define En_set EN =1 #define DATAPORT P0/*------------------------------------------------a busy function--------------------------- 
 ---------------------*/bit lcd_check_busy (void) {#ifdef check_busy dataport= 0xFF; 
 _nop_ ();
return (BIT) (dataport & 0x80);
#else return 0; #endif}/*------------------------------------------------write the command function----------------------------------------
 --------*/void lcd_write_com (unsigned char Com) {//while (Lcd_check_busy ());//Busy Waiting for delayms (5); 
 dataport= com; 
 _nop_ ();
 EN_CLR; }/*------------------------------------------------write Data functions------------------------------------------------*/void Lcd_write_data (unsigned char Data) {//while (Lcd_check_busy ());//Busy Waiting for delayms (5); 
 Dataport= Data;
 _nop_ ();
 EN_CLR; }/*------------------------------------------------clear function---------------------------------------------- 
 --*/void Lcd_clear (void) {lcd_write_com (0x01);
 Delayms (5); }/*------------------------------------------------write a string function----------------------------------------------- -*/void lcd_write_string (unsigned char x,unsigned char y,unsigned char *s) {if (y = = 0) {LCD_WR     Ite_com (0x80 + x);      Represents the first row} else {lcd_write_com (0xC0 + x);     
 Represents the second row} while (*s) {lcd_write_data (*s);     
    s + +; }/*------------------------------------------------write the character function--------------------------------------------- ---*/* void Lcd_write_char (unsigned char x,unsigned char y,unsigned char DATA) {if (y = = 0) {lcd_write_com (0x80 + x);     
    } else {lcd_write_com (0xC0 + x);  
 } lcd_write_data (Data); }*//*------------------------------------------------initialization function-----------------------------------------------    -*/void Lcd_init (void) {lcd_write_com (0x38); 
   /* Display Mode settings */delayms (5); 
   Lcd_write_com (0x38); 
   Delayms (5); 
   Lcd_write_com (0x38); 
   Delayms (5);  
   Lcd_write_com (0x38);    Lcd_write_com (0x08);    /* Show off */lcd_write_com (0x01);    /* Display Clear screen */lcd_write_com (0x06); 
   /* Display cursor movement settings */delayms (5);    Lcd_write_com (0x0C);
 /* Display open and cursor settings */}

② delay function

#include "delay.h"/
 US delay function with input parameters unsigned char T, no return value
 unsigned char is defined as an unsigned character variable whose value range is
 0~255 here use crystal oscillator 12M, accurate delay use assembly, approximate delay
 length as follows t=tx2+5 US 
------------------- -----------------------------*/
void delayus2x (unsigned char t)
 while (--t);
 ms delay function with input parameters unsigned char T, no return value
 unsigned char is to define an unsigned character variable whose value range is
 0~255 here use crystal oscillator 12M, accurate delay use assembly
/ void delayms (unsigned char t)

     //approximate delay 1mS
     delayus2x (245);
     DELAYUS2X (245);

③ The following is the main function

#include <reg52.h>//contains header files, the general situation does not need to change, the header file contains the Special function register definition #include "1602.h" #include "delay.h" Sbit ir=p3^2;
Infrared interface Flag Char code tab[16]= "0123456789ABCDEF"; /*------------------------------------------------global variable Declaration------------------------------------------------
*/unsigned char irtime;//infrared with global variable bit irpro_ok,irok;
unsigned char ircord[4];

unsigned char irdata[33];
unsigned char tempdata[16]; /*------------------------------------------------function declaration------------------------------------------------
*/void Ir_work (void);

void Ircordpro (void); /*------------------------------------------------Timer 0 Interrupt processing--------------------------------------------  ----*/void Tim0_isr (void) Interrupt 1 using 1 {irtime++; Used to count the time between 2 falling edges}/*------------------------------------------------external Interrupt 0 interrupt processing-----------------------      -------------------------*/void Ex0_isr (void) interrupt 0//external interrupt 0 service function {static unsigned char i;       receiving infrared signal processing static bit startflag; Whether to start processing the flag bit if (Startflag) {if (irtime<63&&irtime>=33)//boot code TC9012 header code, 9ms+4.
            5ms i=0;
            The irdata[i]=irtime;//stores the duration of each level for later determination of 0 or 1 irtime=0;
                 if (i==33) {irok=1;
        }} else {irtime=0;
        startflag=1; }/*------------------------------------------------timer 0 Initialization----------------------------------------- -------*/void Tim0init (void)//Timer 0 initialization {tmod=0x02;//Timer 0 mode of operation 2,th0 is the reload value, TL0 is the initial values th0=0x00;//load value tl0=0x00;//Initialization value ET    0=1;    
Open interrupt tr0=1; }/*------------------------------------------------external interrupt 0 initialization------------------------------------------   ------*/void Ex0init (void) {IT0 = 1;   Specifies an external interrupt 0 falling edge trigger, INT0 (P3.2) EX0 = 1;    Enable external interrupt EA = 1; Total Interrupt}/*------------------------------------------------key Value Processing------------------------------------------------*/V   OID ir_work (void) {tempdata[0] = tab[ircord[0]/16];
       Processing Customer code TEMPDATA[1] = tab[ircord[0]%16];
       TEMPDATA[2] = '-';   TEMPDATA[3] = tab[ircord[1]/16];
       Processing Customer code TEMPDATA[4] = tab[ircord[1]%16];
       TEMPDATA[5] = '-';   TEMPDATA[6] = tab[ircord[2]/16];
       Processing data code TEMPDATA[7] = tab[ircord[2]%16];
       TEMPDATA[8] = '-';   TEMPDATA[9] = tab[ircord[3]/16];

       Processing data anti-code TEMPDATA[10] = tab[ircord[3]%16];

       Lcd_write_string (5,1,tempdata); irpro_ok=0;//processing Completion Flag}/*------------------------------------------------infrared Code value processing-----------------------
  -------------------------*/void Ircordpro (void)//Infrared Code value processing function {unsigned char I, j, K;

  unsigned char cord,value;
       for (i=0;i<4;i++)//Processing 4 bytes {for (j=1;j<=8;j++)//processing 1 bytes 8 bits {Cord=irdata[k];   if (cord>7)//is greater than a value of 1, this and crystal oscillator has an absolute relationship, here using 12M calculation, this value can have a certain error value|=0x80;
            if (j<8) {value>>=1;
         } k++;
     } Ircord[i]=value;     
     value=0; } irpro_ok=1;//handle finished flag position 1}/*------------------------------------------------main function-------------            -----------------------------------*/void Main (void) {ex0init ();           Initialize external interrupt tim0init ();           Initialize timer lcd_init ();          Initialize the LCD delayms (20);          Delay helps stabilize lcd_clear ();
 Clear Screen lcd_write_string (0,0, "");

 Lcd_write_string (0,1, "Code:");
       while (1)//main loop {if (Irok)//If received well for infrared processing {ircordpro ();
      } if (IRPRO_OK)//If the work is processed after processing, such as the corresponding key after the display of the corresponding number {ir_work (); }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.