Abstract: By analyzing the waveforms sent by the buttons of the infrared remote control, the pattern can be identified, which provides a basis for software decoding. This article introduces the hardware interface between the infrared remote controller and the single chip microcomputer with examples, and gives the software decoding method from the principle. This is a successful example that can be directly cited, and also provides a very practical reference for the development and application of various infrared remote controllers in microcontroller control products. |
In the development and application of MCU control products, in order to control commands to the control system software, a keyboard is often indispensable. The traditional method is to use the parallel input / output interface chip to expand a keyboard interface, or directly use the parallel port of the microcontroller to expand. In some application environments, there are two disadvantages of this method: â‘ The keyboard and the control system are connected together, which is inflexible, and the environment adaptability is poor; â‘¡ The ports of the microcontroller are wasted, and the hardware cost is relatively high.
Using infrared remote control as the input device of the control system has the characteristics of low cost, flexibility and convenience. The purpose of this article is to introduce the general method of software decoding research and the application technology of infrared remote control for secondary development. This method has been successfully implemented in multiple application system designs with good results.
Infrared remote control is a very easy to buy and cheap product, there are many types, but they are all matched with a specific electronic product (such as various TVs, VCDs, air conditioners, etc.), which are decoded by a dedicated CPU Can be used directly as a general single-chip microcomputer control system. To use the ready-made remote control as the input of the control system, the following problems need to be solved: how to receive the infrared remote control signal; how to recognize the infrared remote control signal; and the design of the decoding software. Other problems are non-essential. For example, the problem of labeling the function keys on the remote control panel can be designed and reprinted by yourself.
1 Infrared remote control signal reception
The receiving circuit can use an integrated infrared receiver. The receiver includes an infrared receiver tube and a signal processing IC. The receiver has only 3 pins: Vcc, GND and 1 pulse signal output PO. It is very convenient to interface with the microcontroller, as shown in Figure 1.
â‘ Vcc is connected to the positive pole of the power supply of the system (+ 5V);
â‘¡GND connects to the system ground (0V);
â‘¢The pulse signal output is connected to the interrupt input pin of the CPU (for example, the 13-pin INT1 of 8031). With this connection method, the software solution can work both in the query mode and the interrupt mode.
2 Pulse flow analysis
To understand an unknown remote control, we must first analyze its pulse stream, so as to understand its pulse waveform characteristics (how to carry "0" and "1" information), and then understand its encoding law. The analysis of the pulse flow should start from the analysis of the high and low width of the pulse. The author uses the software method to realize the analysis of the pulse flow. Taking the interface shown in Figure 1 as an example, if no infrared remote control signal arrives, the output port PO of the receiver remains high; when an infrared remote control signal is received, the signal of the receiving device is converted into a pulse sequence and added to the interrupt input of the CPU. foot. Test the logic level of the pin with software, and start the TC timer at the same time, measure the time value of the case where the pin is logic "0" and logic "1", store it, and then print and analyze. The following is a program segment for collecting and storing the pulse stream in 8051 assembly language:
MOV R0, # 00H
MOV R1, # 28H
MOV TMOD, # 01H
TK: JB P3.3, TK; wait for the low level to arrive
; Measuring low level width
TK1: MOV TH0, # 00H
MOV TL0, # 00H
SETB TR0
TK0: JB TF0, TKE; invalid return after timeout
JNB P3.3, TK2
CLR TR0
MOV A, TH0
MOVX @ R0, A
INC R0
MOV A, TL0
MOVX @ R0, A
INC R0
; Measure high level width
MOV TH0, # 00H
MOV TL0, # 00H
SETB TR0
TK3: JB TF0, TKE; invalid return after timeout
JB P3.3, TK3
CLR TR0
MOV A, TH0
MOVX @ R0, A
INC R0
MOV A, TL0
MOVX @ R0, A
INC R0
DJNZ R1, TK1; loop
TKE: RET
This program first sets TC0 to the 16-bit timer mode, initializes the RAM address pointer R0 and the loop count pointer R1, and whenever the logic level of the pin changes, stops the timing and saves the timing value to the continuous RAM . This program can continuously measure the time value of 40 pulses (including 40 low-level pulse widths). The author took the remote controller of TC9012 chip as the object, collected the programming pulse waveform of all the keys, and repeated the experiment on the same key. Due to space limitations, the sampling data cannot be given, only the law of pulse flow (the crystal frequency of the simulator CPU is 6MHz):
①The guide pulse is a low level with a time value of 0937H ~ 0957H and a high level with a time value of 084FH ~ 086FH;
② The low-level time value of the data pulse is about 0.127H ~ 0177H;
③ There are 2 cases of high level time value: 00BBH ~ 00FFH (narrow), 02EFH ~ 0333H (wide).
Summarized and analyzed by a large amount of data, the key coding has the following rules:
â‘ The pulses other than the pilot pulse are data-encoded pulses, and the data "bit" information is determined by the high-level pulse width: the narrow pulse width indicates "0" and the wide pulse width indicates "1";
â‘¡ After decoding the pulse stream of each button, it contains 4 bytes of information:
* The encoding of the first 2 bytes of all keys is the same, both are "0EH" of 2 bytes;
* The third byte is the key code;
* The fourth byte is the inverse of the key code.
After multiple samplings of the same key pulse, it is found that the pulse width time value of the corresponding position of the same key pulse sequence fluctuates within a small range (not a certain value). Therefore, the precise comparison method cannot be adopted for pattern recognition. In this regard, I took an obscure approach to abstract processing. According to the above experimental rules, the basis for analyzing and judging pulses during software decoding and algorithm design ideas are summarized as follows:
â‘ The judgment level of the low-level and high-level width of the pilot pulse is the "high byte greater than 08H" of the time value, and the low byte is ignored;
â‘¡ The low-level pulse width of the data pulse stream is the same, and it is ignored if it is ignored;
â‘¢ High-level pulse width is the basis for judging whether each bit of the data stream is "0" or "1". My judgment is that if the high byte of the pulse width is less than 2, it means "0", otherwise it means "1", and the low byte of the pulse width is ignored.
Practice has proved that the above criteria are effective and feasible. Such processing not only simplifies the design of the decoding software, but also greatly improves the speed of decoding. When using the above criteria to write a software decoding program, pay attention to the correspondence between the pulse stream sampling data storage address and the pulse. The software mainly has the following parts:
â‘ Judge the arrival of the remote control signal (call an independent subroutine before decoding);
â‘¡ Sampling and storing pulse flow;
â‘¢ Determine whether the pilot pulse is valid;
â‘£ Decode the first 2 bytes and judge whether it is "0EH";
⑤ Decode the third byte, which is the effective key code;
â‘¥ Lookup table mapping of key codes (if the original key codes are used, this step can be omitted).
3 Design of decoding software
The software decoding system designed based on the above ideas is successfully applied to multiple control systems. The assembly language program of an example (using MCS-51 series MC traffic rules TC9012 infrared remote control for software decoding) is given below. The parameters used in the program are for the MCU using a 6MHz crystal. If you use a crystal of other frequency, you only need to modify the pulse width criterion. For ease of understanding, try to keep the consistency with the principle narrative, a more detailed translation of the notes is given in the program, see the online supplement (http: //) for details.
Although this article is to use MCS-51 series MCU to decode the TC9012 infrared remote control software, the method is general. The specific application is flexible.
SHAOXING COLORBEE PLASTIC CO.,LTD , https://www.fantaicolorbee.com