Abstract: This paper combines the design practice of infrared communication in multi-rate electric energy meter, introduces the software and hardware design method of infrared communication in single-chip microcomputer system, and gives the specific circuit principle and communication source program.
Keywords: single-chip microcomputer, infrared communication, remote control
In many application systems based on single-chip microcomputer, the system needs to realize remote control function, and infrared communication is a method that is widely used. The remote control protocol on the market is simple, the confidentiality is not strong, and the anti-interference ability is weak. Here, we introduce an infrared remote control system based on byte transmission, which can be suitable for various complex applications.
The basic principle of infrared communication
The basic principle of infrared communication is that the transmitter modulates the baseband binary signal into a series of pulse train signals and transmits the infrared signal through the infrared transmitting tube. Commonly used methods are pulse width modulation (PWM) that realizes signal modulation by pulse width and pulse time modulation (PPM) that realizes signal modulation by the time interval between pulse trains. This system adopts the permanent time system method. The transmission of data bits imitates RS232 communication without odd-side check. First, a synchronization header is generated, followed by 8 data bits.
Hardware circuit design
The multi-rate energy meter system can be divided into two parts: the handheld remote control and the multi-rate energy meter. The handheld remote control is the transmitting part, and its basic circuit is shown in Figure 2. The plastic-encapsulated SE303ANC-transmitting diode is used, and the wavelength is 940nm. The CPU turns on or off the transmitting diode according to the protocol, thereby generating a transmitting signal of a specific frequency. The frequency selected here is 38.9kHz. The basic circuit of the infrared receiving part of the multi-rate energy meter is shown in Figure 3. The receiving tube uses the PIC-12034 of Japan Optoelectronics Company, and its receiving frequency is 37.9kHz. It directly demodulates the 37.9kHz modulated signal into a baseband signal and provides a ribbon receiving CPU. The chip has high receiving sensitivity and stable performance. Its basic working process is: when receiving a 37.9kHz signal, it outputs a low level, otherwise it outputs a high level. The energy meter part uses a 51 series single-chip microcomputer, which detects the received signal in an interrupt mode. The NOT gate here plays a shaping role on the received signal.
Software Design
The program of the transmitting part is relatively simple, mainly producing 37.9kHz pulse train signals with different time intervals to control the on and off of the transmitting tube. At the transmitting end, the CPU continuously scans the keyboard. Once a key is pressed, the transmitting subroutine is started to send out the corresponding value. In our design, a 4×4 small keyboard is used. Just as it corresponds to the 0~F code, in order to improve reliability, the simplest error correction code is used-sending each digit repeatedly, that is, the code corresponding to the keyboard number is 00~FF. In this way, a key value needs to send 8 bits. After the receiving end receives the full 8-bit signal, it will perform error correction processing, and incorrect codes are considered invalid. After receiving the specified number, the number analysis program is called for processing. When a pulse train signal is received, a timer is started. When the next interrupt occurs, the count value of the timer is used to determine whether it is 0 or 1. If the timer overflows, the number received this time is cleared and restored to the initial state of reception. The basic program flow of the receiving part is shown in Figure 4.
When designing the program, it should be noted that the MCU interrupt mode uses falling edge triggering: the receiving end uses the T0 count value to determine the transmitted bit, and generally uses hard judgment, that is, the average value of the 0 and 1 bit widths is taken as the decision threshold A. When the T0 value is greater than A, the received signal is judged to be 0, and when it is less than A, it is judged to be 1.
The infrared receiving program in the multi-rate electric energy meter (MCU is Intel 8052, written in C language) is shown in the program list.
Conclusion
The above design scheme has been applied to the multi-rate electric energy meter, and the effect is good, meeting the design requirements. The whole system has few peripheral components, which is convenient for debugging; the software workload is also small. If it is used to transmit a large amount of data, the corresponding encoding form can be changed as needed to increase the data transmission rate.
Communication source program
#include
#include
#include
#pragma OPTIMIZE(5,SPEED)
sbit RECV=P3^3;
bdata unsigned char SIGN,RECVBYTE;
sbit RECVBG=SING^0;
sbit US1AT=SIGN^6;
sbit RECVBITO=RECVBYTE^0;
unsigned char RECVBIT;
∥
timer0() interrupt 1 ∥ entry:8*n+3=0Bh;
{
IE=0x8d; ∥ 1(EA)0(X)0(X)0(X)-1(ET1)1(EX1)0(ET0)1(EX0)
RECVBG=0;
}
∥
EX-INT1() interrupt 2 ∥ receive infrared signal
{
TCON=0x45; ∥0(TF1)1(TR1)0(TF0)1(TR0)-0(IE1)1(IT1)0(IE0)1(IT0)
If(RECVBG==0) {RECVBG=1;
RECVBIT=8;
}
eles{BECVBYTE=RECVBYTE<<1;
if(TH0<=4)RECVBIT0=1;
else RECVBIT0=0;
RECVBIT--;
If( IT==0) {RECVBG=0;
US1AT=1;
}
}
TH0=0;
TL0=0;
TCON=0x55; ∥0(TF1)1(TR1)
0
(TF0)1(TR0)-0(IE1)1(IT1)0(IE0)1(IT0)
IE
=
0x8f;
RECVBYTE=O;
SIGN=O;
TMOD=0x11;
TCON=0x55; ∥0(TF1)1(TR1)0(TF0)1(TR0)-0(IE1)1(IT1)0(IE0)1(IT0)
IP=0x00;
IE=0x8d; ∥1(EA)0(X)0(X)0(X)-1(ET1)1(EX1)0(ET0)1(EX0)
∥Basic loop program
while(1) {
..
(Omitted)
.
if(US1AT==1{∥Infrared receiving processing
.
.(Omitted)
.
}
}
}
Previous article:Introduction to MCU and its development history
Next article:The basic principle of stepper motor
- Popular Resources
- Popular amplifiers
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
- BTT6030-2EKA
- Several C language algorithms commonly used in single chip microcomputers
- There is no problem with the amplifier output.
- Mobile Wi-Fi: How wireless routers can help catch thieves
- Sensor detection circuit advice
- GC0308 camera circuit
- Disassembling a Highly Advanced Negative Ion Air Purifier
- GD32E231 Learning 5: Color Sensor Module GY-31 Test
- Help
- Can modules be used in electric racing?