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 receiving tube, a crystal oscillator 11.0592MHz, 4 electrolytic capacitors 10uF, a 10uF, a 1K resistor, a 300 ohm resistor, and 2 ceramic capacitors 30P. 8 light-emitting diodes. The price is less than 20 yuan.
Circuit principle introduction:
The main control unit is the AT89C2051 microcontroller. The interrupt port INT0 is connected to the infrared receiving tube U1 to receive the pulse of the infrared signal. The 8 light-emitting diodes are used as display decoding outputs (can also be used to expand other control circuits). U3 is the level conversion chip when connected to the computer serial port RS232. Pins 9 and 10 are connected to pins 1 and 2 of the microcontroller respectively (pin 1 is serial receiving and pin 2 is serial sending). Pins 7 and 8 of MAX232CPE are connected to pins 2 (receiving) and 3 (sending) of the computer serial port respectively. The crystal oscillator uses 11.0592MHz, so that the baud rate of 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, and 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.
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 high 4 bits with the low 4 bits
mov r1,a ;//Save to R1
anl tl0,#0f0h ;//Take the high 4 bits of TL0 and ignore the low 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 low 4 bits of TH0 and the high 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 to collect
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, it meets the bit "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 count 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 code is 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 it matches, 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 for sending to be completed
clr ti ;//Sending completed, clear TI
exit0: ;//
ljmp main ;//Loop
keycode: ;//Each two bytes represent the code 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,01000 000b db
11111011b,01100000b, 11111111b,01100000b, 11111111b,10100000b
db 10001100b,10001110b, 10001101b,11101110b, 10001100b,10101110b
db 10001101b,11001110b, 11111000b,11100000b, 11111100b,10 000000b
db 11111100b,01000000b, 11111001b,10100000b, 11111100b,10100000b
db 11111100b,01100000b
end
-------------------------------------------------- -------------------------------
Different remote controllers have different codes. If you use other remote controllers, modify a few Parameters are enough (of course the button encoding table must be different), that is, the value of the counter is different, but some remote controls have machine codes (the machine code is the same for each button), in this case you can skip the collection of the machine code. Finally, I want to mention that it was quite troublesome at first when I didn’t know the coding of the remote control. I downloaded a sound card oscilloscope from the “Ssangyong Electronics” website, which allowed me to view the waveform of the remote control at a glance and measure its pulse width. It is indeed much more convenient to have it. The software can be downloaded for free from the Ssangyong 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 by yourself Or you can directly download and use the Girder software, which is specially designed for serial remote controls and is very easy to use. The download address is: http://www.girder.nl/. You can use this software to define the remote control Remotely control your computer to move the mouse, keyboard operations, browse the Internet, open the player, shut down, etc.
Previous article:ST7920 12864 Classic Function
Next article:Infrared remote control microcontroller coding program plus detailed explanation
Recommended ReadingLatest update time:2024-11-16 22:32
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- If you don’t lose weight in spring, you will regret it in summer. Let me share some tips on how to lose weight and keep in shape!
- [Embedded Linux] RK3399 Android7.1 CPU is overheating
- 【Chuanglong TL570x-EVM】Button control LED light
- TI Automotive SPD-SmartGlass Driver Reference Design
- Start with a simple board
- iwr1642
- How to export Altium's customize settings for backup
- Why is FPGA difficult to learn?
- Why does the DIY capacitor spot welder have no current after spot welding once?
- Tsinghua University successfully developed a brain-computer interface system that can play football with the mind