To decode the infrared remote control signal, you need to use the C51 external interrupt and set it to the negative transition edge trigger mode. Generally, the interrupt is initialized outside the beginning of the main program (or the initialization interrupt program is written as a function and this function is placed in the main program) as follows:
void main(void)
{
.........//Other programs
..........
}
void INT0() interrupt 0
{
.......//Infrared signal decoding program
}
Enable external interrupt as needed (EX0=1):
The above program opens the external interrupt at the beginning. Theoretically, it is completely correct! But in reality, it depends on the specific situation to open the external interrupt! If you just enter the program to handle other things and cannot process infrared signals temporarily, then EX0=1 cannot be written at the beginning of the main program. It should be written in an appropriate position. Otherwise, when the infrared signal is turned on, it will immediately enter the infrared signal decoding program.
Disable external interrupt (EX0=0):
Once there is an interrupt signal, the microcontroller will quickly respond to the interrupt and enter the interrupt program. The interrupt program is also the infrared signal decoding program. In the interrupt program, don't forget to turn off the interrupt EX0=0! After pressing a button on the remote control, the remote control will send data out in groups. Even if you press and release the button at the fastest speed, the remote control has sent out multiple groups of data. The microcontroller will decode multiple times. If the main program is relatively large, the decoded data will be overwritten by the next data before it can be used in a hurry! After turning off the external interrupt, it can effectively avoid interference and distinguish whether the current group of data has been received and decoded! When entering the interrupt program, turn off the external interrupt, and turn on the external interrupt after a group of data is decoded and adopted by the main program. This is a complete process! This complete process can be completed normally without interference. In reality, interference is everywhere. Once the data cannot be decoded normally, the main program will not use it, and the external interrupt will no longer be turned on. It will no longer receive infrared signals. At this time, add a judgment at the end of the infrared decoding program. If an error occurs, turn on the external interrupt at the end of the decoding program to prepare for the next infrared signal.
Clear IE0 as needed (IE0=0):
After the interrupt is turned off, the remote control does not stop sending signals. The infrared signal after the interrupt is turned off will continue to set IE0. The state of IE0 is not controlled by EX0 at all. The single-chip microcomputer executes the IT1=1 statement. As long as the external interrupt has a negative transition edge, IE0 will be set. If we only process the signal after EX0=1 (that is, the signal after the interrupt is turned on), then IE0 must be cleared before the infrared signal decoding program exits. If it is not cleared, as long as the external interrupt is turned on, the interrupt will be entered again. This time, entering the interrupt will waste time at best, and may cause errors (which are very obvious when the infrared decoding uses the query method after entering the interrupt). Therefore, a sentence IE0=0 should be added before EX0=1.
Previous article:C51 Interruption Experience
Next article:The basis of C51 key program writing
Recommended ReadingLatest update time:2024-11-16 14:37
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
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
- [GD32E231 DIY Contest] Part 4: Summary
- EPWM interrupt cannot be enabled
- Three closed loop servo motor motion control
- Two-input AND gate engineering files and test files
- Help others and achieve self-realization——EEWORLD Q&A List (11th issue)
- ST Motor Review_bygyp1
- Problem of assigning initial value to timer of C51 MCU
- UPS-IPGuard Pro P1902 front panel device wiring diagram:
- 2012 Competition Award-winning Papers, Source Code, PCB (Part 5)
- DCDC Chip