Home > Microcontroller >Microcontroller Production > Decoding infrared remote control using microcontroller

Decoding infrared remote control using microcontroller

Source: InternetPublisher:三月小雨 Updated: 2013/07/30

Use microcontroller to decode infrared remote control. The remote control is easy to use and has many functions. It has been widely used in various household appliances such as televisions, VCDs, DVDs, and air conditioners. It is cheap and easily available in the market. If you can decode many buttons on the remote control. Used as input to the microcontroller system. It solves the shortcomings of conventional matrix keyboard circuit boards that are too large, have complicated wiring, and occupy too many I/O ports. And by using the remote control, the person and the device can be separated during operation, making it more convenient to use. The following takes the remote control of the TC9012 encoding chip as an example. Let’s talk about how to use the commonly used 51 system microcontroller to decode remote control. 1. The signal transmitted by the encoding format 1, 0 and 1 of the remote control consists of a string of binary codes of O and 1. Different chips encode 0s and 1s differently. Usually there are Manchester encoding and pulse width encoding. The O and 1 of TC9012 are encoded using the PWM method, that is, pulse width modulation. The O code and 1 code are shown in Figure 1 (taking the waveform of the remote control reception output as an example). O code consists of O. It is a combination of 56ms low level and 0.56ms high level. The pulse width is 1.12ms. 1 code is composed of 0.56ms low level and 1.69ms high level. The pulse width is 2.25ms. When writing a decoding program. By judging the width of the pulse, you can get 0 or 1. 2. Button coding When we press the button of the remote control, the remote control will send out a string of binary codes as shown in Figure 2, which we call a frame of data. According to the function of each part. They can be divided into 5 parts, namely boot code, address code, address code, data code, and data inverse code. When the remote control transmits a code. They are all low first. The high position is behind. It can be obtained from the analysis of Figure 2. The high level of the boot code is 4.5ms, and the low level is 4.5ms. When receiving this code. Indicates the beginning of a frame of data. The microcontroller can prepare to receive the following data. The address code consists of 8-bit binary, with a total of 256 types. The address code in the picture has been resent. Mainly to enhance the reliability of the remote control. If the two address codes are not the same. It means that the data of this frame is wrong. Should be discarded. Different devices can have different address codes. therefore. Remote controls with the same encoding will not interfere with each other as long as they are set with different address codes. The address code in the picture is 0EH in hexadecimal (note that the low bit comes first). in the same remote control. The address codes sent by all keystrokes are the same. The data code is 8 bits and can encode 256 states, representing the actual key pressed. Data complement is the inversion of each bit of the data code, by comparing the data code with the data complement. Can determine whether the received data is correct. If the relationship between the data code and the data complement does not satisfy the opposite relationship. Then the remote control reception is incorrect this time. The data should be discarded. on the same remote control. The data codes for all keys are different. In Figure 2, the data code is 0CH in hexadecimal, and the inverse data code is 0F3H in hexadecimal (note that the low bit comes first). The sum of the two should be 0FFH. 2. Single-chip microcomputer remote control receiving circuit Infrared remote control reception can use the earlier method of infrared receiving diodes and dedicated infrared processing circuits. For example, CXA20106, this method has complicated circuit and is generally not used now. A better receiving method is to use an integrated infrared receiver, which combines infrared receiving diodes, amplification, demodulation, shaping and other circuits with only three pins. They are +5V power supply, ground and signal output. The appearance and pins of commonly used integrated receivers are shown in Figures 3 and 4. The signal output of the infrared receiver is connected to the INTO or INTl pin of the microcontroller. The typical circuit is shown in Figure 5. In the figure, a PNP transistor is added to amplify the output signal. 3. Decoding algorithm and programming of remote control signals. There are no keys to press on the remote control. The infrared emitting diode does not emit a signal, and the remote control receiver outputs signal 1. When a key is pressed. The high level coded by O and 1 will output the signal O after being inverted by the remote control head. Because it is connected to the interrupt pin of the microcontroller, it will cause an interrupt to the microcontroller (the microcontroller is preset to generate an interrupt on the falling edge). The microcontroller uses timer 0 or timer 1 to start timing when interrupted. When the next pulse arrives, that is, when an interrupt occurs again, the timing value is taken out first. Start timing again after clearing the timing value. By judging the time interval between each interruption and the previous interruption. Then you can know whether the boot code or O and 1 is received. If the timing value is 9ms. What is received is the pilot code. If the timing value is equal to 1.12ms, what is received is code O. If the timing value is equal to 2 25ms. Code 1 was received. When judging time, a certain error value should be considered. Because different remote controls have small errors in the transmission and reception times due to crystal oscillator parameters and other reasons. Taking receiving the TC9012 remote control code as an example, the decoding method is as follows: (1) Set external interrupt 0 (or 1) as a falling edge interrupt, and timer 0 (or 1) as a 16-bit timer. The initial values ​​are all O. (2) After entering the remote control interrupt for the first time, the timing starts. (3) Starting from the second remote control interruption, the timing will be stopped first. And save the timing value before re-timing. If the timing value is equal to the preamble time, the preamble flag is set. Prepare to receive the following frame of remote control data. If the timing value is not equal to the time of the preamble, but the preamble has been received previously, determine whether it is O or 1 of the remote control data. (4) Continue to receive the following address code, data code, and data inverse code. (5) When 32-bit data is received, it means that one frame of data has been received. At this time, you can stop the timer and determine whether this reception is valid. If twice address

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号