Microcontroller as infrared remote control decoder

Publisher:NatureLoverLatest update time:2014-12-31 Source: 51heiKeywords:MCU 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 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.

Keywords:MCU Reference address:Microcontroller as infrared remote control decoder

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

Design of DC power collection charger based on single chip microcomputer
  In recent years, the problem of energy shortage has become increasingly prominent. While people are worried about energy depletion, the waste of energy is alarming. For example, various discarded batteries, especially those used in remote control toy cars, are discarded before even half of their energy is used. This
[Microcontroller]
Design of DC power collection charger based on single chip microcomputer
Design of water temperature remote control and telemetry system based on single chip microcomputer C8051F040
      IntroductionTemperature      remote control and telemetry is a remote measurement and control of temperature, which is particularly suitable for those places where the environment is harsh and the measurement personnel are not easy to approach. In recent years, it has been widely used in industrial and agricultur
[Microcontroller]
Design of water temperature remote control and telemetry system based on single chip microcomputer C8051F040
Design of DC motor speed measurement program based on PIC microcontroller
In Capture mode, the CCPRxH:CCPRxL register pair captures the 16-bit value of the TMR1 register or the TMR3 register when an event occurs on the corresponding CCPx pin. An event is defined as one of the following: Each falling edge Each rising edge Every 4 rising edges Every 16 rising edges u Select the event type b
[Microcontroller]
Design of DC motor speed measurement program based on PIC microcontroller
Design of Electric Bicycle Controller Based on XC866 Series Microcontroller
This solution is based on the 8-bit single-chip SAF-XC846 + IPP120N06, Infineon XC866 series microcontroller, with a clock rate of 27 MHz, 6-way PWM designed for motors, high-speed analog-to-digital converters and other high-performance peripheral functions, suitable as a motor control core unit, and is in
[Microcontroller]
Design of Electric Bicycle Controller Based on XC866 Series Microcontroller
PIC Microcontroller for Beginners (Part 1)
Learning PIC microcontroller   for beginners  (Part 1): The pain and joy of writing driver for TS1620 character LCD module    I have been studying PIC16F87X series microcontrollers for half a month, and I have encountered many difficulties. Fortunately, there are some related books in the library of my unit, and I hav
[Microcontroller]
Microcontroller introductory experiment seven
;************************************************; ;Experiment name: 1 independent keyboard controls LED light experiment            ; ;Author:                          Long Yi                                ; ;Version:                        VER 1.0                            ; ;Description:              Beginner'
[Microcontroller]
51 single chip microcomputer c language --- delay
1. _nop_() is suitable for a small delay at the us level There is no empty statement in the standard C language. However, in C language programming of microcontrollers, it is often necessary to use several empty instructions to produce a short delay effect. This is easy to achieve in assembly language, just write a f
[Microcontroller]
51 MCU Study Notes [I] - LED Light Experiment
LED lamp is a kind of light-emitting diode, with forward voltage drop of 1.6V~2.2V and current of 2~20mA. When the current is 2~5mA, the brightness increases with the increase of current. When the current exceeds 5mA, the brightness does not change. When the current exceeds 20mA, the lamp is damaged. This experiment u
[Microcontroller]
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号