Design of infrared remote control decoder

Publisher:Mingyue1314Latest update time:2012-11-06 Source: 21ic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Do you have a TV remote control or an air conditioner remote control at home? Do you also want to use it to control other appliances or even your computer? Well, let's make this "infrared remote control decoder" together with me.

This small production requires very few components: a TA89C2051 microcontroller, a MAX232CPE RS232 interface level and TTL level conversion chip, an infrared receiver, a crystal oscillator 11.0592MHz, 4 electrolytic capacitors 10uF, a 10uF, a 1K resistor, a 300 ohm resistor, 2 ceramic capacitors 30P, and 8 light-emitting diodes. The price is less than 20 yuan.

Circuit principle introduction:
The main control unit is the single-chip microcomputer AT89C2051, the interrupt port INT0 is connected to the infrared receiving tube U1 to receive the pulse of the infrared signal, and the 8 light-emitting diodes are used as display decoding output (it can also be used to expand other control circuits), U3 is the level conversion chip when connected to the computer serial port RS232, and the 9th and 10th pins are connected to the 1st and 2nd pins of the single-chip microcomputer respectively (1st pin is serial receiving, 2nd pin is serial sending), and the 7th and 8th pins of the MAX232CPE are connected to the 2nd (receiving) pin and 3rd (sending pin) of the computer serial port respectively. The crystal oscillator uses 11.0592MHz, so that the baud rate of the communication can reach 9600b/s. The general default value of the computer is 9600b/s, 8 data bits, 1 stop bit, and no parity bit. The circuit is so simple, now let's analyze the specific programming process.
As shown in the figure, the waveform of the panasonic remote control is like this (the result of repeated tests).
The start bit is a 3.6ms low level followed by a 3.6ms high level. The data representation is a 0.9ms low level, 0.9ms high level, and a period of 1.8ms for "0", and a 0.9ms low level, 2.4ms high level, and a period of 3.3ms for "1". When writing a program, a high level greater than 3.4ms and less than 3.8ms is used as the start bit, a high level greater than 2.2ms and less than 2.7ms is used to represent "1", and a high level greater than 0.84ms and less than 1.11ms is used to represent "0". Therefore, we mainly use the microcontroller to measure the length of the high level to determine whether it is "1" or "0". The working mode of timer 0 is set to mode 1: mov tmod, #09h. Setting timer 0 in this way means setting GATE to 1, a 16-bit counter, and a maximum count value of 2 to the 16th power of machine cycles. This mode is controlled by the external interrupt INT0, that is, the counter is allowed to count only when INT0 is high. For example:
jnb p3.2, $
jb p3.2, $
clr tr0
these three instructions can measure a high level, and then read the count value TH0, TL0 to distinguish whether it is the start bit or "1" or "0". Before determining the code table, you can use the 8 light-emitting diodes of the P0 port to display the code. The 16-bit code is displayed twice:
mov p0, keydata
acall delay_1s; //1ms delay subroutine
mov p0, keydata+1
ljmp main
According to the two consecutive codes displayed by P0, record the code of each key to form a code table, that is, the decoding of the remote control code is completed. After the code table is determined, after receiving the remote control code, it will be compared with the code table to find the matching code item, and the sequence number corresponding to the code item will be output to the P0 port, and the sequence number will also be output to the computer through the serial port. After the computer receives the data, the serial port software will decide how to process it. [page]

The program is not long, here is the complete program and comments: (see the flow chart first)
keydata equ 30h ; //This address and address 31H are used to store the remote control key code.
org 00h
main:
mov keydata,#0 ;// clear
mov tmod ,#09h ;// set timer 0 mode 1, GATE=1
mov r7,#0 ;// counter, used to count whether it is full of 8 bits
mov r6,#0 ;// counter, used to count whether it is full of 2 bytes (decode 16 bits)
jb p3.2,$ ;// is it low level
again: ;// if it is low, continue to execute below
mov tl0,#0 ;// clear TL0
mov th0,#0 ;// clear TH0
setb tr0 ;// start timer 0
jnb p3.2,$ ;// wait for high level to arrive
jb p3.2,$ ;// high level arrives, start counting at this time
clr tr0 ;// high level ends, stop counting
mov a,th0 ;// read th0 value, TL0 is ignored
clr c ;//
subb a,#12 ;//
jc again ;//If th0<12, then turn, which means it is less than 3.4ms, you can calculate this time
mov a,#14 ;//
clr c ;//
subb a,th0 ;//Compare with 14, if TH0>14, it is greater than 3.8ms
jc again ;//Greater than 3.8ms, re-detect
nextbit: ;//The start bit is found, then the next bit
mov tl0,#0 ;//
mov th0,#0 ;//
setb tr0 ;//Start timer
jnb p3.2,$ ;//Wait for high level
jb p3.2,$ ;//High level arrives, then start counting
clr tr0 ;//High level ends, stop counting
mov a,th0 ;//Read the count value, TL0 is ignored
clr c ;//
subb a,#8 ;//Compare th0 with 8
jc next ;;;;//If <2.2ms, then jump and determine whether it is greater than 0.84ms
mov a,#10 ;//Compare with 10 again
clr c ;//
subb a,th0 ;//
jc again ;;;;;;;//If >2.7ms, give up and re-detect
mov a,keydata ;// If it is greater than 2.2ms and less than 2.7ms, it is "1"
setb c ;//C = 1
rrc a ;//Shift 1 into A
mov keydata,a ;//Save
inc r7 ;//Counter plus 1
cjne r7,#8,nextbit ;//Is it full of 8 bits
inc r6 ;//Count plus 1
cjne r6,#2,last8 ;//Is it full of two bytes
sjmp seach ;//If it is less than two bytes, collect last8 again
: ;//Full of 1 byte, then the next byte
mov keydata+1,a ;//Save the first byte of encoded data to 31h
mov r7,#0 ;//Clear counter R7
sjmp nextbit ;//Continue collecting data
next: ;//Go here when less than 2.2ms
mov a,th0 ;//Read count value TH0
swap a ;//Swap the upper 4 bits with the lower 4 bits
mov r1,a ;//Save to R1
anl tl0,#0f0h ;//Take the upper 4 bits of TL0 and ignore the lower 4 bits
mov a,tl0 ;//
clr c ;//
rrc a ;//
rrc a ;//
rrc a ;//
rrc a ;//
add a,r1 ;//
mov r1,a ;//
subb a,#30 ;//The above lines combine the lower 4 bits of TH0 and the upper 4 bits of TL0 into 1 byte as the count value
jc nextbit ; //Judge whether it is <0.84ms, if yes, give up and continue sampling
mov a,r1 ;//No
clr c ;//
cjne a,#64,continue ;//Compare with 64
continue: ;//
jnc nextbit ; //a>64 means the sampling value is >1.11ms give up
mov a,keydata ;//Otherwise, the matching bit is "0"
clr c ;//C = 0
rrc a ;//shift zero right into A
mov keydata,a ;//save
inc r7 ;//counter plus 1
cjne r7,#8,nextbit ;//is it full 8 bits
inc r6 ;//counter plus 1
cjne r6,#2,last_8 ;//the first byte is full
sjmp seach ;//
last_8: ;//if it is the second byte
mov keydata+1,a ;//save the first byte to 31h
mov r7,#0 ;//clear R7
sjmp nextbit ;//
seach: ;//match key code
mov r0,#-2 ;//key code byte number counter
mov r1,#-1 ;//key sequence counter
seach1: ;//
inc r0 ;//
seach2: ;//
inc r0 ;//
inc r1 ;//
cjne r1,#29,compare ;//Is R1=29
sjmp exit0 ;//
compare: ;//start matching
mov a,r0 ;//
mov dptr,#keycode ;//address pointer points to the first address of the code table
movc a,@a+dptr ;//get code
cjne a,keydata,seach1 ;//compare
inc r0 ;//R0+1, then compare the next byte (each key is encoded as 2 bytes)
mov a,r0 ;//
;mov dptr,#keycode ;//
movc a,@a+dptr ;//compare
cjne a,keydata+1,seach2 ;//match or not, if not match, continue to compare with the next byte
mov p1,r1 ;//if match, output the key sequence number to p1
send: ;//
mov tmod,#20h ; //Set timer 1,mode 2
mov tl1,#0fdh ;//Set the initial value of the timer
mov th1,#0fdh ;//
mov scon,#01010000b;//The above settings set the serial port baud rate coefficient to: 9600,8,1,0
setb tr1 ;//Start timer 1
loop_s: ;//
mov sbuf,r1 ;//Output R1 (key sequence number) to the serial port
jnb ti,$ ;//Wait to see if the transmission is completed
clr ti ;//Sending is completed, clear TI
exit0: ;//
ljmp main ;//Loop

keycode: ;//Each two bytes represent the encoding of a key
db 11111000b,00000000b, 11111100b,00000000b, 11111001b,11000000b
db 11111100b,11000000b, 11111010b,0000000b, 11111010b,00100000b
db 11111010b,01000000b, 11111010b,01100000b, 11111010b,10000000b
db 11111010b,10100000b, 11111010b,11000000b, 11111010b,11100000b
db 11111011b,00000000b, 11111011b,00100000b, 11111011b,01000000b
db 11111011b,01100000b, 11111111b,01100000b, 11111111b,10100000b
db 10001100b,10001110b, 10001101b,11101110b, 10001100b,10101110b
db 10001101b,11001110b, 11111000b,11100000b, 11111100b,10000000b
db 11111100b,01000000b, 11111001b,10100000b, 11111100b,10100000b
db 11111100b,01100000b
end
---------------------------------------------------------------------------------
Various remote controllers have different encodings. If you use other remote controllers, you can just modify a few parameters (of course the button encoding table must be different), that is, the value of the counter is different. However, some remote controllers have machine codes (the machine codes are the same for each button). In this case, you can skip the collection of the machine code. Finally, I want to mention that it is troublesome to not know the remote control code at the beginning. I downloaded a sound card oscilloscope from the "Shuanglong Electronics" website. With it, I can see the waveform of the remote control and measure its pulse width at a glance. It is indeed much more convenient. The software can be downloaded and used for free at the Shuanglong company website http://www.sl.com.cn/. If you want to control the computer with a remote control, you can write a serial port application software yourself, or you can directly download and use the Girder software, which is specially made for serial port remote control and is very easy to use. The download address is: http://www.girder.nl/. You can use this software to define the remote control to remotely control your computer to move the mouse, keyboard operation, browse the Internet, open the player, shut down, etc.

Reference address:Design of infrared remote control decoder

Previous article:Infrared remote control decoding program written in C language
Next article:Dual-machine communication (C language, master and slave shared program)

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号