Microcontroller infrared remote control decoding program

Publisher:HeavenlyLoveLatest update time:2011-12-06 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Infrared remote control is the most widely used communication and remote control method. Since infrared remote control devices have the characteristics of small size, low power consumption, strong functions and low cost, after color TVs and video recorders, other small electrical appliances such as recorders, audio equipment, air conditioners and toys have also adopted infrared remote control. Now it has also been widely used in industrial equipment.

1 Infrared remote control system

The universal infrared remote control system consists of two parts: the transmitting part and the receiving part. The encoder/decoder special integrated circuit chip is used for control operation, as shown in Figure 1. The transmitting part includes the keyboard matrix, coding modulation, and LED infrared transmitter; the receiving part includes the optical-electric conversion amplifier, demodulation, and decoding circuits.

2 Remote control transmitter and its coding

There are many special chips for remote control transmitters, which can be divided into two categories according to the coding format: pulse width modulation and pulse phase modulation. Here we use pulse width modulation, which is widely used and easier to decode, to explain the coding principle. Now we take 3310 as an example to illustrate the coding principle of the transmitter circuit. When the transmitter button is pressed, a remote control code is sent out. The remote control code is different for different keys. This remote control code has the following characteristics:

The serial code adopts pulse width modulation, with a pulse width of 0.565ms, an interval of 0.56ms, and a period of 1.125ms representing the binary "0"; and a pulse width of 0.565ms, an interval of 1.685ms, and a period of 2.25ms representing the binary "1".

The 42-bit binary code composed of "0" and "1" is modulated twice by a 38kHz carrier frequency to improve the transmission efficiency and reduce power consumption. Then the infrared emitting diode generates infrared rays and transmits them into space.

The remote control code generated by 3310 is a continuous 42-bit binary code group, of which the first 26 bits are the user identification code, which can distinguish different infrared remote control devices and prevent the remote control codes of different models from interfering with each other. The last 16 bits are the 8-bit operation code and the 8-bit operation inverse code, which are used to check whether the data is received accurately.

When any button on the remote control is pressed for more than 36ms, the oscillator of the LC7461 chip activates the chip and transmits a specific synchronization terminal, which is a 9ms low level and a 4.5ms high level for the receiving end. This synchronization terminal allows the program to know that it can start receiving data from this synchronization terminal.

The key to decoding is how to identify "0" and "1". From the definition of the bit, we can find that "0" and "1" both start with a low level of 0.56ms, but the difference is that the width of the high level is different, "0" is 0.56ms, "1" is 1.68ms, so "0" and "1" must be distinguished according to the width of the high level. If the delay starts after the 0.56ms low level, after 0.56ms, if the read level is low, it means that the bit is "0", otherwise it is "1". For reliability, the delay must be longer than 0.56ms, but not more than 1.12ms, otherwise if the bit is "0", the read level is already the next high level, so (1.12ms+0.56ms)/2=0.84ms is the most reliable, and generally about 0.84ms is sufficient.

According to the infrared coding format, the program should wait for the 9ms start code and 4.5ms result code to complete before reading the code.

Receiver and Decoder

LT0038 is a plastic-encapsulated integrated infrared receiver. It is an integrated circuit that integrates infrared reception, amplification and shaping. It does not require any external components to complete all the work from infrared reception to output compatible with TTL level signals. It is high level when there is no infrared remote control signal and low level when receiving an infrared signal. Its size is the same as that of an ordinary plastic-encapsulated triode. It is suitable for various infrared remote controls and infrared data transmission.

The following is a decoding program for the infrared remote control that comes with the 51ISP programming experimental development board. It can read the key value of each button on the infrared remote control and display it through the 8 LEDs on the P1 port of the experimental board. When the decoding is successful, it can also emit a "beep beep" prompt.

[page]

ORG 0000H
AJMP MAIN; transfer to the main program
ORG 0003H; external interrupt P3.2 pin INT0 entry address
AJMP INT; transfer to the external interrupt service subroutine (decoding program)
; the following is the CPU interrupt mode setting for the main program
MAIN: SETB EA; open the CPU total interrupt request
SETB IT0; set the trigger mode of INT0 to pulse negative edge trigger
SETB EX0; open INT0 interrupt request
; the following initializes all pins of the microcontroller and sets them all to high level
MOV P2,#11111111B
AJMP $

;The following is to enter the P3.2 pin external interrupt subroutine, that is, the decoding program
INT: CLR EA ;Temporarily turn off all CPU interrupt requests
MOV R6,#10
SB: ACALL YS1;Call 882 microsecond delay subroutine
JB P3.2,EXIT;After a delay of 882 microseconds, determine whether a high level appears on the P3.2 pin. If so, exit the decoding program
DJNZ R6, SB;Repeat 10 times. The purpose is to detect if a high level appears within 8820 microseconds and exit the decoding program
;The above completes the recognition of the 9000 microsecond initial low-level signal of the remote control signal.
JNB P3.2, $ ;Wait for a high level to avoid a 9-millisecond low-level guide pulse
ACALL YS2 ;Delay 4.74 milliseconds to avoid a 4.5-millisecond result code

MOV R7, #26; Ignore the first 26 bits of the system identification code

JJJJA:JNB P3.2,$; Wait for the high level signal of the first bit of the address code
LCALL YS1; After the high level starts, use the time ruler of 882 microseconds to judge the high and low level status of the signal at this time
MOV C,P3.2; Store the current level status of the P3.2 pin 0 or 1 in C
JNC UUUA; If it is 0, jump to UUUA
LCALL YS3; If a high level 1 is detected, delay 1 millisecond to wait for the high level of the pulse to end
UUUA: DJNZ R7,JJJJA

MOV R1,#1AH; Set 1AH as the starting RAM area
MOV R2,#2; Receive 2 memories from 1AH to 1BH to store the operation code and the inverse operation code
PP: MOV R3,#8; Each group of data is 8 bits

JJJJ: JNB P3.2,$; Wait for the high level signal of the first bit of the address code
LCALL YS1; After the high level starts, use a time ruler of 882 microseconds to determine the high and low level states of the signal at this time
MOV C,P3.2; Store the current level state of the P3.2 pin 0 or 1 in C
JNC UUU; If it is 0, jump to UUU
LCALL YS3; If a high level 1 is detected, delay 1 millisecond to wait for the high level of the pulse to end
UUU: MOV A,@R1; Give the address in R1 to A
RRC A; Move the value 0 or 1 in C to the lowest bit in A
MOV @R1,A; Temporarily store the number in A in the memory of R1 value
DJNZ R3,JJJJ; Receive a full 8-bit memory
INC R1; Add 1 to the value in R1 and change to the next RAM
DJNZ R2,PP; After receiving the 8-bit data code and the 8-bit data inverse code, store them in 1AH/1BH

MOV A,1AH
CPL A; invert 1AH and compare it with 1BH
CJNE A,1BH,EXIT; if they are not equal, it means an error occurred in receiving data, and give up

MOV P1,1AH; Display the key value through the 8 LEDs of P1 port!
CLR P2.0; The buzzer beeps, indicating that the decoding is successful
LCALL YS2
LCALL YS2
LCALL YS2
SETB P2.0; Stop the buzzer (When using, you can use the YINYUE pin of J2 to connect the XS1 pin of J4 with a jumper to use the buzzer) See the schematic diagram
EXIT: SETB EA; Allow interrupt
RETI; Exit the decoding subroutine

YS1: MOV R4,#20 ; Delay subroutine 1, accurate delay of 882 microseconds
D1: MOV R5,#20
DJNZ R5,$
DJNZ R4,D1
RET
YS2: MOV R4,#10 ; Delay subroutine 2, accurate delay of 4740 microseconds
D2: MOV R5,#235
DJNZ R5,$
DJNZ R4,D2
RET
YS3: MOV R4,#2; Delay subroutine 3, accurate delay of 1000 microseconds
D3:MOV R5,#248
DJNZ R5,$
DJNZ R4,D3
RET
END
The above programs are for reference only.

0A 01
11 12 13 14
15 16 17 18
19 10 1A 1B
0E 02 03 1C
06 04 05 0C
0D 08 09 1D
00 1F 1E 0B
07 0F

This is the key value (in hexadecimal) of the 32 keys according to the actual position of the infrared remote control keys.

Reference address:Microcontroller infrared remote control decoding program

Previous article:STC12C5410 MCU Simulation for Multimedia Projector Remote Control
Next article:What I want to say to microcontroller beginners

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号