Infrared remote controller decoding method and device
By simplifying the infrared remote control decoding method, the Bit bit and address code are directly judged, and the problems of complexity in the existing technology and large resource occupancy are solved, and low performance requirements and efficient infrared remote control decoding are achieved.
Patent Information
- Application Number
- CN202411688517.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-25
- Publication Date
- 2024-12-20
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The decoding technology of existing infrared remote controls is complex and takes up a lot of microcontroller resources, which is difficult for ordinary engineers to decode, and has high performance requirements.
An infrared remote control decoding method is adopted, through the INT1 interrupt service function combined with the timer to continuously interrupt the receiving of NEC code commands within a specified time, directly determine that the Bit bit is "0" or "1", and there is no need to judge whether the boot header and 32Bit are received. Complete, simplify the decoding process, using a single timer without writing interrupt programs.
It realizes simple, easy to understand and reliable infrared remote control decoding, reduces the requirements for microcontroller performance and occupies less resources, allowing ordinary microcontrollers and general-level engineers to decode.
Smart Images

Figure CN119169796A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to infrared remote control decoding technology in the field of electrical appliance control and data transmission, and in particular to an infrared remote control decoding method and device. Background Art
[0002] A large number of electrical appliances on the market are still controlled by infrared remote controls. Although infrared remote controls are simple, reliable, and easy to use, infrared remote control decoding is still relatively complex. Take the NEC protocol infrared remote control decoding as an example. Figure 1 As shown, the NEC code protocol includes a guide header and an infrared remote control code. The guide header consists of a 9ms low level and a 4.5ms high level. A complete infrared remote control code is 4 bytes: 1Byte infrared remote control address code; 1Byte infrared remote control address code inverse code; 1Byte infrared remote control key code; 1Byte infrared remote control key code inverse code. Figure 1 In the code, LSB represents the low bit, MSB represents the high bit, 1 and 0 represent the high level and low level, and the numbers with horizontal lines in the inverse code of the address code and the inverse code of the key code represent the inverted high level and low level. Figure 2 For the existing NEC code infrared remote control decoding method, see Figure 2 It can be seen that the current NEC code infrared remote control decoding algorithm needs to judge: the guide head, the high and low level time of each bit pulse, and whether the bit is "0" or "1"; the above process is processed in the interrupt program; the 32-bit data will be decoded in the main program only after it is received. It is judged that it is the remote control address of this device, and the address code is equal to the address inverse code, and the data code is equal to the data code inverse code, that is, the complete remote control transmission code is decoded. In this program, the high and low level time judgment of the bit is "0" or "1" requires a timing interrupt program. And the code must be written in the timing interrupt program to judge the high and low level time. Among them, the guide head is judged to first receive a low level of 9ms, and then receive a high level of 4.5ms. Figure 3 The figure is a schematic diagram of the level signal of logic "1" and logic "0" in the prior art. The total time length of logic "1" is 2.25ms, of which the first part is 560μs high level and the second part is 1680μs low level; the total time length of logic "0" is 1.12ms, of which the first part is 560μs high level and the second part is 560μs low level. It can be seen that the existing infrared remote control decoding has high performance requirements for the single-chip microcomputer, occupies more resources, and is difficult for engineers of general level to decode. Summary of the invention
[0003] The technical problem to be solved by the present invention is as follows: In view of the above-mentioned problems in the prior art, a method and device for decoding an infrared remote control are provided. The present invention aims to provide an infrared remote control decoding mechanism which is simple, easy to understand, reliable, has low performance requirements on a single-chip microcomputer, and occupies less resources, so that ordinary single-chip microcomputers and engineers of general level can use it for decoding.
[0004] In order to solve the above technical problems, the technical solution adopted by the present invention is: An infrared remote controller decoding method includes the following steps: starting a timer, initially setting a 32-bit complete NEC code data ircode to 0, a 32-bit timer capture value capt1 to 0, a 32-bit decoded remote controller key code ircodeset to 0, a logic "0" time T_Bit0, and a logic "1" time T_Bit1; continuously interrupting 34 times within a specified total time to receive a complete NEC code command through an INT1 interrupt service function combined with a timer timing value TMRCNT, wherein the steps executed by each interrupt of the INT1 interrupt service function include: S1, assign the timer timing value TMRCNT to the timer capture value capt1; S2, determine whether the timer capture value capt1 is less than the time T_Bit0 of the logic "0", if so, jump to the next step; S3, shift the complete NEC code data ircode left by 1 bit and set it to zero; S4, determine whether the timer capture value capt1 is less than the time T_Bit1 of the logic "1", if so, jump to the next step; S5, shift the complete NEC code data ircode left by 1 bit, and increment the complete NEC code data ircode by 1; S6, judging whether the complete NEC code data ircode complies with the NEC code specification, if it complies with the NEC code specification, jumping to the next step; S7, assigning the complete NEC code data ircode to the decoded remote control key code ircodeset, and assigning the complete NEC code data ircode to 0; S8, clear the timer value TMRCNT of the timer, clear the overflow flag of the timer, and return from the INT1 interrupt.
[0005] Optionally, determining whether the complete NEC code data ircode complies with the NEC code specifications in step S7 includes: determining whether the complete NEC code data ircode complies with the NEC code specifications in step S7 includes: determining whether the received 4 bytes of data include a 1-byte infrared remote control address code, a 1-byte infrared remote control address code's inverse code, a 1-byte infrared remote control key code and a 1-byte infrared remote control key code inverse code, and whether the infrared remote control address code is the local address; if so, determining that the complete NEC code data ircode complies with the NEC code specifications; otherwise, determining that the complete NEC code data ircode does not comply with the NEC code specifications.
[0006] Optionally, the frequency of the timer is 100KHz.
[0007] Optionally, the infrared remote controller decoding method is executed by a single-chip microcomputer, and the timer is executed without setting an interrupt.
[0008] Optionally, the infrared remote controller decoding method is executed by a single chip microcomputer, and the timer is executed in a way of setting an interrupt, and the interrupt program of the timer is to execute the timer value TMRCNT to increase by 1.
[0009] Optionally, the time T_Bit0 of the logic "0" is 1.2 ms, and the time T_Bit1 of the logic "1" is 2.4 ms.
[0010] Optionally, the specified total time is 10 microseconds.
[0011] In addition, the present invention also provides an infrared remote controller decoding device, comprising a single chip microcomputer and an infrared receiver connected to each other, wherein the single chip microcomputer is programmed or configured to execute the infrared remote controller decoding method.
[0012] In addition, the present invention also provides a computer-readable storage medium, in which a computer program or instruction is stored. The computer program or instruction is programmed or configured to execute the infrared remote controller decoding method through a processor.
[0013] In addition, the present invention also provides a computer program product, including a computer program or instructions, wherein the computer program or instructions are programmed or configured to execute the infrared remote controller decoding method through a processor.
[0014] Compared with the prior art, the present invention mainly has the following advantages: the present invention does not need to judge the guidance head, nor does it judge whether the 32 bits are received. It directly judges whether the received bit is "0" or "1", and then judges whether it is the local address, and judges whether the complete NEC code data ircode meets the specifications of the NEC code (the address code is equal to the address inverse code, and the data code is equal to the data code inverse code), that is, the complete remote control transmission code is decoded. The above program is completed in the interrupt program, and a timer is required. The timer does not need to write an interrupt program. The method is simple, easy to understand, reliable, has low performance requirements on the single-chip microcomputer, and occupies less resources. The infrared remote control decoding mechanism allows ordinary single-chip microcomputers and engineers of general level to decode. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 It is a protocol diagram of NEC code in the prior art.
[0016] Figure 2 The figure is a flow chart of a method for decoding an infrared remote controller of NEC code in the prior art.
[0017] Figure 3 It is a schematic diagram of the level signals of logic "1" and logic "0" in the prior art.
[0018] Figure 4 It is a schematic diagram of the decoding process of each interrupt execution in an embodiment of the present invention. DETAILED DESCRIPTION
[0019] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments.
[0020] The present embodiment provides an infrared remote controller decoding method, comprising the following steps: starting a timer, initially setting a 32-bit complete NEC code data ircode to 0, a 32-bit timer capture value capt1 to 0, a 32-bit decoded remote controller key code ircodeset to 0, a logic "0" time T_Bit0, and a logic "1" time T_Bit1; using an INT1 interrupt service function combined with a timer timing value TMRCNT to continuously interrupt 34 times within a specified total time to receive a complete NEC code command, such as Figure 4 As shown, the steps of each interrupt execution of the INT1 interrupt service function include: S1, assign the timer timing value TMRCNT to the timer capture value capt1; S2, determine whether the timer capture value capt1 is less than the time T_Bit0 of the logic "0", if so, jump to the next step; S3, shift the complete NEC code data ircode left by 1 bit and set it to zero; S4, determine whether the timer capture value capt1 is less than the time T_Bit1 of the logic "1", if so, jump to the next step; S5, shift the complete NEC code data ircode left by 1 bit, and increment the complete NEC code data ircode by 1; S6, judging whether the complete NEC code data ircode complies with the NEC code specification, if it complies with the NEC code specification, jumping to the next step; S7, assigning the complete NEC code data ircode to the decoded remote control key code ircodeset, and assigning the complete NEC code data ircode to 0; S8, clear the timer value TMRCNT of the timer, clear the overflow flag of the timer, and return from the INT1 interrupt.
[0021] In step S7 of this embodiment, judging whether the complete NEC code data ircode complies with the specifications of the NEC code includes: judging whether the complete NEC code data ircode complies with the specifications of the NEC code includes: judging whether the received 4 bytes of data include 1-byte infrared remote control address code, 1-byte infrared remote control address code's inverse code, 1-byte infrared remote control key code and 1-byte infrared remote control key code inverse code, and whether the infrared remote control address code is the local address; if so, judging that the complete NEC code data ircode complies with the specifications of the NEC code; otherwise, judging that the complete NEC code data ircode does not comply with the specifications of the NEC code. In step S7 of this embodiment, judging whether the complete NEC code data ircode complies with the specifications of the NEC code is equivalent to a fuzzy judgment method, which does not require precise judgment of several time values in the NEC protocol, so the logic is very simple.
[0022] In this embodiment, the frequency of the timer is 100KHz. The timer is started in the main program, and the periodic timing is at a frequency of 100KHz. The execution subject of the infrared remote control decoding method is a single-chip microcomputer, and the timer is executed in a manner without setting an interrupt. Since the timer does not set an interrupt, there is no need to write a timing interrupt program. In addition, as another optional implementation, some single-chip microcomputers may need to enter a timing interrupt program. The execution subject of the infrared remote control decoding method is a single-chip microcomputer, and the timer is executed in a manner of setting an interrupt, and the interrupt program of the timer is to execute the timer value TMRCNT to increase by 1: TMRCNT=TMRCNT+1.
[0023] In this embodiment, the specified total time is 10 microseconds, the entire program takes less than 10 microseconds, and only 34 interrupts are required to receive a complete infrared remote control code command.
[0024] In this embodiment, the time T_Bit0 of logic "0" is 1.2ms, and the time T_Bit1 of logic "1" is 2.4ms. These two values can achieve fault tolerance.
[0025] This embodiment uses the INT1 interrupt service function combined with the timer timing value TMRCNT to continuously interrupt 34 times within the specified total time to receive a complete NEC code command, as detailed below: The first interrupt: The value of TMRCNT is random. If it is greater than T_Bit1, it will be discarded. If it is a valid "0" or "1", it will participate in the shift calculation. In the end, this value will become the 33rd bit of the remote control receiving code and will be squeezed out by the following 32 bits of mobile data; therefore, the first interrupt does not need to determine whether it is the start of the reception of the guide bit. The second interrupt: It is the guide bit, and the time data is greater than T_Bit1, and this value will be discarded. The third interrupt: It is a valid "0" or "1"; it participates in the shift calculation; it is the first bit of the remote control receiving code. The fourth interrupt: It is a valid "0" or "1"; it participates in the shift calculation; it is the second bit of the remote control receiving code. Enter the interrupt reception decoding in sequence; ...; Finally, the 34th interrupt: This is triggered by the 0.56ms stop bit. At this time, the timing data TMRCNT belongs to the 32nd data of the remote control receiving code. The complete infrared decoded data is completely received. In this embodiment, the interrupt program triggered by the falling edge of the infrared receiver pin level is specifically written.
[0026] The common decoding algorithm is to decode strictly according to the protocol requirements of the NEC code, usually relying on the interrupt program to decode. It takes tens of milliseconds to decode an infrared remote control code, and the logic is complex, occupying more MCU resources. Usually, the execution time of the interrupt program is short, and the real-time performance of the system is strong. The long decoding time is not conducive to the real-time processing of other events. The biggest difference between the method of this embodiment and the existing method is in the following points: 1. The method of this embodiment calculates the time between two low levels, that is, the time of the previous bit. Instead of judging the time of the current bit in the existing algorithm. 2. There is no need to judge the guide header; 3. Identify the value of the bit immediately; 4. Judge whether the decoding is successful at any time. There is no need to receive 32 bits and then decode. The method of this embodiment does not need to accurately judge several time values in the NEC protocol. It only needs to judge whether the received 4 bytes of data meet the following conditions: 1Byte infrared remote control address code; 1Byte infrared remote control address code inverse code; 1Byte infrared remote control key code; 1Byte infrared remote control key code inverse code; (the address code of the infrared remote control is in the program and is a fixed constant). Therefore, the logic of this embodiment is very simple: the received address code is correct; the inverse of the address code is correct; the inverse of the remote control code received first is equal to the remote control code received later; then the remote control decoding event ends. The code is also very simple: a few statements; the execution time is also very short: dozens of microseconds.
[0027] To sum up, the present invention does not need to judge the guidance head, nor does it judge whether the 32 bits are received. It directly judges whether the received bit is "0" or "1", and then judges that it is the local address, and the address code is equal to the address inverse code, and the data code is equal to the data code inverse code, that is, the complete remote control transmission code is decoded. The above program is completed in the interrupt program, and a timer is required. The timer does not need to write an interrupt program. The method is simple, easy to understand, reliable, has low performance requirements on the single-chip microcomputer, and occupies less resources. The infrared remote control decoding mechanism can be decoded by ordinary single-chip microcomputers and engineers of general level.
[0028] In addition, the present invention also provides an infrared remote controller decoding device, comprising a single chip microcomputer and an infrared receiver connected to each other, wherein the single chip microcomputer is programmed or configured to execute the infrared remote controller decoding method. The infrared remote controller decoding device can be used for various electrical devices such as televisions and set-top boxes that use infrared remote controllers.
[0029] In addition, the present invention also provides a computer-readable storage medium, in which a computer program or instruction is stored. The computer program or instruction is programmed or configured to execute the infrared remote controller decoding method through a processor.
[0030] In addition, the present invention also provides a computer program product, including a computer program or instructions, wherein the computer program or instructions are programmed or configured to execute the infrared remote controller decoding method through a processor.
[0031] Those skilled in the art should understand that the technical solutions provided by the embodiments of the present application may be in the form of methods, systems, or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may take the form of a computer program product implemented on one or more computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes. The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the process Figure 1 A process or multiple processes and / or boxes Figure 1These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including an instruction device, which implements the functions specified in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide for implementing the process in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0032] The above is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technicians in this technical field, some improvements and modifications without departing from the principle of the present invention should also be regarded as the protection scope of the present invention.
Claims
1. A method for decoding an infrared remote controller, characterized in that: The method comprises the following steps: starting a timer, initially setting a 32-bit complete NEC code data ircode to 0, a 32-bit timer capture value capt1 to 0, a 32-bit decoded remote control key code ircodeset to 0, a logic "0" time T_Bit0, and a logic "1" time T_Bit1; and continuously interrupting 34 times within a specified total time to receive a complete NEC code command by combining an INT1 interrupt service function with a timer timing value TMRCNT. The steps executed by each interrupt of the INT1 interrupt service function include: S1, assign the timer timing value TMRCNT to the timer capture value capt1; S2, determine whether the timer capture value capt1 is less than the time T_Bit0 of the logic "0", if so, jump to the next step; S3, shift the complete NEC code data ircode left by 1 bit and set it to zero; S4, determine whether the timer capture value capt1 is less than the time T_Bit1 of the logic "1", if so, jump to the next step; S5, shift the complete NEC code data ircode left by 1 bit, and increment the complete NEC code data ircode by 1; S6, judging whether the complete NEC code data ircode complies with the NEC code specification, if it complies with the NEC code specification, jumping to the next step; S7, assigning the complete NEC code data ircode to the decoded remote control key code ircodeset, and assigning the complete NEC code data ircode to 0; S8, clear the timer value TMRCNT of the timer, clear the overflow flag of the timer, and return from the INT1 interrupt.
2. The infrared remote controller decoding method according to claim 1, characterized in that: In step S7, determining whether the complete NEC code data ircode complies with the NEC code specification includes: determining whether the received 4-byte data includes a 1-byte infrared remote control address code, a 1-byte infrared remote control address code's inverse code, a 1-byte infrared remote control key code and a 1-byte infrared remote control key code inverse code, and whether the infrared remote control address code is the local address; if so, determining that the complete NEC code data ircode complies with the NEC code specification; otherwise, determining that the complete NEC code data ircode does not comply with the NEC code specification.
3. The infrared remote controller decoding method according to claim 1, characterized in that: The frequency of the timer is 100KHz.
4. The infrared remote controller decoding method according to claim 1, characterized in that: The infrared remote controller decoding method is executed by a single chip microcomputer, and the timer is executed in a manner of not setting an interrupt.
5. The infrared remote controller decoding method according to claim 1, characterized in that: The infrared remote controller decoding method is executed by a single chip microcomputer, and the timer is executed in a way of setting an interrupt, and the interrupt program of the timer is executed to increase the timing value TMRCNT of the timer by 1.
6. The infrared remote controller decoding method according to claim 1, characterized in that: The time T_Bit0 of the logic "0" is 1.2 ms, and the time T_Bit1 of the logic "1" is 2.4 ms.
7. The infrared remote controller decoding method according to claim 1, characterized in that: The specified total time is 10 microseconds.
8. An infrared remote controller decoding device, comprising a single chip microcomputer and an infrared receiver connected to each other, characterized in that: The single chip microcomputer is programmed or configured to execute the infrared remote controller decoding method according to any one of claims 1 to 7.
9. A computer-readable storage medium having a computer program or instruction stored therein, characterized in that: The computer program or instruction is programmed or configured to execute the infrared remote controller decoding method according to any one of claims 1 to 7 through a processor.
10. A computer program product comprising a computer program or instructions, characterized in that The computer program or instruction is programmed or configured to execute the infrared remote controller decoding method according to any one of claims 1 to 7 through a processor.
