1. System composition and functions
This system consists of two parts: measurement and transmission and reception and display. The measurement and transmission part completes the sampling and analog-to-digital conversion of analog electrical quantity, and sends the converted data through the serial port, modulating the wireless transmission circuit to transmit it. The receiving part receives the wireless information, amplifies and shapes the serial data signal, and sends it to the serial port of the single-chip microcomputer of the receiving part. After the single-chip microcomputer successfully receives the data information in the agreed format, it is converted into a display code and sent to the LED for display. The measurement and display parts are separated.
2. Principle of power measurement and data transmission
The principle of measuring and transmitting circuit is shown in Figure 1. The analog quantity to be measured is input from P1.1 of IC1 (AT89C2051). After the system completes the measurement, it stores the data in accumulator A, and then sends the data in A to the serial port, outputs it through P3.1 (TXD), and transmits the data information through the modulated wireless transmitting circuit.
We have already discussed the analog-to-digital conversion in the measurement process in the previous issue. We can learn the wireless transmission circuit and modulation principle from other books or other methods, so we will not repeat them here. The following focuses on the setting of the microcontroller serial port and the serial port data output format.
Both AT89C51 and AT89C2051 have a high-performance programmable full-duplex serial communication interface, referred to as the serial port. It is very convenient to send and receive data using this serial port. There are two registers for sending and receiving data, namely the send SBUF and the receive SBUF. These two registers use the same address 99H, but the send and receive do not conflict because the send and receive instructions can distinguish them. When the CPU executes MOV SBUF, A, the data in accumulator A is written into the send SBUF; and when executing MOV A, SBUF, the CPU reads the data in the receive SBUF into accumulator A. After the data to be sent is written into SBUF, the serial port send controller automatically outputs the data from P3.1 in a certain format and baud rate. The most commonly used serial output format is the 11-bit format. This format stipulates that the complete data frame output by the serial port consists of 11 bits of binary data. The frame structure diagram is shown in Figure 2 (a). First, send 1 bit of data "0" as the start character of the data to be sent, and then send each data bit of the 8-bit byte to be sent, with the low bit first. That is, send D0 first, then send D1, D2, D3, D4, D5, D6, D7 in sequence, and then send a special bit that can be defined, such as the parity bit "P" or a data bit with other meanings. This special bit is the 10th bit of the entire data frame. After the 10th bit is sent, then output 1 bit of data "1" as the end character of the data frame. If the data value is #87H is sent in 11-bit serial format, the square wave output by P3.1 is shown in Figure 2 (b). This square wave controls the conduction and cutoff of VT1 and modulates the data to the transmitting circuit. For the convenience of everyone's production, this example connects the infrared transmitting circuit that transmits data information to the serial port, so that the infrared light-emitting tube VD1 is modulated by VT1. In this way, the data information output by P3.1 is modulated onto the infrared carrier. The VT1 collector waveform is shown in Figure 2 (c), and the modulated infrared optical carrier sequence is shown in Figure 2 (d).
The working mode and working status of the serial port can be defined by the program. The register that determines the output format and working status of the serial port is the serial port control register SCON, whose address is 98H. The definition of each bit of SCON is shown in the attached table.
Schedule
D7 D6 D5 D4 D3 D2 D1 D0
SM0 SM1 SM2 REN TB8 RB8 TI RI
SM0 and SM1 are the serial port working mode selection bits. By defining SM0 and SM1, the serial port can be determined to have four working modes: mode 0 (00), mode 1 (01), mode 2 (10), and mode 3 (11). Since this example uses an 11-bit serial format and selects the serial port to work in mode 2, SM0 is set to "1" and SM1 is set to "0". MOV SCON, #80H at 0000H in the program list completes the above settings. In the simple communication experiment where the serial port works in mode 2, SM2, TB8, and RB8 do not need to be concerned. REN and RI are the receive enable bit and the receive interrupt flag bit, respectively, and their functions will be explained in the receiving part. TI is the transmit interrupt flag. When the transmit controller sends a frame of data, it automatically sets TI to "1". After the program finds that TI is set to "1", it confirms that the data has been sent, clears TI to "0", and then executes other programs. See 000AH in the program list. Three no-operation instructions are temporarily placed at 0005H to 0007H. You can put the call measurement subroutine instruction here, so that the program for measuring the emission part is complete. It is not difficult to see from the program that MOV A, #87H at 0003H makes the data in accumulator A #87H. MOV SBUF, A at 0008H sends the data in A to the serial port transmission register. In this way, data #87H is output in 11-bit format through P3.1, pushing VT1 and modulating VD1 to transmit the infrared carrier string carrying data. It's just that the real measurement program is omitted in the program list, and the analog measurement method is used to send data. The above program makes the baud rate of the serial port 93.75Kb/s, that is, 93750 bits of binary data can be sent per second. This rate is relatively high. At this rate, it is reliable to modulate the infrared transmitting tube to send data, while modulating the general simple high-frequency oscillation circuit is too high. Therefore, if you want to use a simple high-frequency oscillation circuit to send data, it is reliable to use P3.2 or other lines with other coding rules to send at a low speed. When connected to the "Bluetooth" chip, you can use other lines of the P3 port to communicate with the I 2 C bus protocol.
3. Data reception and display principle
The electrical principle of the receiving and displaying part is shown in Figure 3 (only a simple circuit for infrared receiving is given here).
The infrared ray is received by VD1, and after being amplified and shaped by VT5, the signal is input to P3.0 (RXD) of IC2 (AT89C51). When no infrared information is received, VD1 is in high impedance state, VT5 is cut off, and P3.0 is in high potential. When infrared ray is received by VD1, VD1 is in low impedance state, VT5 is turned on, and P3.0 is pulled to low potential. When VD1 receives a complete data frame with a value of #87H, the collector output waveform of VT5 is shown in Figure 2 (b). Since the serial port of IC2 has the function of automatic reception, when the program allows the serial port to receive, the receiving controller will continuously detect the potential of P3.0. After finding that P3.0 jumps low, it will immediately receive at a certain baud rate according to the set receiving format. When receiving is completed, the data is stored in the receiving SUBF, then the interrupt flag is set, and the RI position of SCON is set to "1". When the program finds that RI is set to "1", it confirms that the reception is completed, clears the flag and turns off the receiving controller, takes out the data in the receiving register SUBF, calls the data processing and scanning display subroutine, and sends the data to the LED for display, thus completing the task of receiving and displaying the measured data. Since the transmitted data adopts the 11-bit format, the reception must also adopt the same format and the same baud rate. Similar to the transmitting part, a MOV SCON, #80H instruction is also placed at 0006H of the receiving program list, so that the SM0 position of SCON is "1" and the other bits are all "0", which makes the serial port of the receiving end CPUIC2 work in mode 2, that is, the 11-bit format. Since no other settings related to the baud rate are made, the receiving rate of the serial port of the receiving part is also 93.75Kb/s. The 5th bit REN of SCON is the receive enable bit. Since this bit has been written to "0" in the instruction for setting the serial port working mode, the serial port reception is prohibited. SETB REN at 0009H in the program list makes the REN position "1", and reception is allowed, which makes the serial port automatically receive, monitors P3.0 and automatically completes the reception. When the reception is completed and the receive interrupt flag RI is cleared, the program should temporarily close the reception to perform data processing and display operations. The CLR REN instruction at 0012H in the program list clears REN to "0", and the serial port reception function is prohibited.
When reception is allowed, the serial port receiving controller can work independently. The program only needs to focus on the receiving interrupt flag. The JBC RI, 0010 and AJMP 000B instructions at 000BH in the program list enable the system to realize the functions of waiting for reception and receiving confirmation before turning to process data. There are 3 empty operation bytes at 0014H in the receiving program, where you can place a subroutine call instruction for data processing and scanning display. The program given in the list can also display the received data. If the data #87H is received correctly, it is directly sent to the P0 port, and then all the port lines of the P2 port are set to high potential, and VT1 to VT4 will all be turned on. In this way, the undecoded data #87H will light up the corresponding field in the LED.
Since #87H is the display code of the number "7.", when the above program is run and #87H is correctly received, LED1 to LED4 will display "7.7.7.7.". Using infrared rays for wireless transmission and reception facilitates hardware debugging-free experiments, making it easier for everyone to set up serial ports and perform programming exercises in sending and receiving data.
The above describes the simple method of setting up the serial port of the microcontroller and using the serial port for communication through a simple wireless test system. In fact, in order to achieve the reliability and accuracy of data transmission during communication, it is often necessary to compile a more complex program to ensure it. There are also some hardware resources inside the microcontroller for developers to use, such as parity check, further setting of baud rate, etc., which will not be described in detail in this article.
In practical application products, the analog-to-digital conversion of the wireless measurement system should use a special high-precision conversion chip, and the performance of wireless transmission and reception, whether infrared or electromagnetic waves, is also relatively good. If a general high-frequency oscillation circuit is used for transmission (such as the high-frequency oscillation circuit given in Figure 1) and a general wireless electromagnetic wave is used for reception, the communication baud rate needs to be lower to be more reliable. At this time, we often do not use the serial port, but use the general I/O line to modulate it according to another communication protocol and encoding method. The principle can refer to the relevant description in the article "Carrier Data Transmission Based on Power Grid" in the 12th issue of "Radio" in 2000. The wireless measurement system we developed is currently undergoing connection tests with the first-generation "Bluetooth" chip "BlueCore TM 01", and is currently designing the second-generation "Bluetooth" chip "BlueCore TM 02" and the third-generation "BlueCore TM 03". Only by mastering certain single-chip microcomputer control technology and using the latest chips as much as possible can we develop leading products. Electronic enthusiasts should also pay attention to this. When you are testing infrared emission data, you can remove the dotted-line portion in Figure 1, and the entire circuit will be very simple.
IV. List of procedures
1. List of procedures for simulation measurement and emission:
Address machine code instruction
0000 759880 MOV SCON, #80H;
0003 7487 MOV A, #87H ;
0005 00 NOP ;
0006 00 NOP ;
0007 00 NOP ;
0008 F599 MOV SBUF, A ;
000A 109902 JBC TI, 000F ;
000D 80FB AJMP 000A ;
000F 20B5FD JB P3.5,000F ;
0012 80EF AJMP 0003 ;
2. Simulate receiving and displaying part of the program list:
Address machine code instruction
0000 75A000 MOV P2, #00H;
0003 758000 MOV P0,#00H;
0006 759880 MOV SCON,#80H;
0009 D29C SETB REN ;
000B 109802 JBC RI,0010 ;
000E 80FB AJMP 000B ;
0010 E599 MOV A, SBUF;
0012 C29C CLR REN ;
0014 00 NOP ;
0015 00 NOP ;
0016 00 NOP ;
0017 F580 MOV P0,A ;
0019 75A0FF MOV P2, #FFH;
001C 7A18 MOV R2, #18H;
001E 7BFF MOV R3, #FFH;
0020 7CFF MOV R4, #FFH;
0022 DCFE DJNZ R4,0022;
0024 DBFA DJNZ R3,0020;
0026 DAF6 DJNZ R2 , 001E ;
0028 75A000 MOV P2 , #00H ;
002B 80DC AJMP 0009 ;
So far, we have used 6 lectures to explain the basic structure and basic principles of single-chip microcomputers from the outside to the inside with examples, and explained some commonly used instructions. You can design some simple control circuits and compile some simple control programs for experiments and further learning. After mastering the basic methods of circuit design and programming, and referring to some related books, and making some more complex circuits, you will be able to complete the design of some reliable control circuits more skillfully, until you develop practical intelligent products, and achieve the purpose of using single-chip microcomputers to create benefits for society.
Editor's note: Starting from the next issue, our magazine will begin to publish articles on the basic knowledge and application examples of PIC series microcontrollers. If you have any suggestions or comments on articles related to microcontrollers, please contact our editorial department by phone or letter.
Previous article:Simply and stably sense you - innovative production of infrared sensor switch
Next article:Using AT89C51 to realize analog-to-digital conversion
- 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
- Xinhua Dictionary of Power Supply--A brief review of the book "Basics of Power Supply Design"
- MSP430 FAQs: Watchdog and Timer
- Chip supply issues
- Do you have more award-winning power banks? If so, please give me one.
- I want to know what this DSA is and why I don't choose a fixed resistance resistor.
- Recommend Chinese chips + domestic ARM and DDR particles (products have been verified and available)
- Review summary: Anxinke NB-IoT development board EC-01F-Kit
- MPS gives benefits | Order online at the mall, get a JD card, and 8,000 yuan worth of gifts are waiting for you!
- The easiest way to achieve the LED breathing light gradually brightening and fading effect, without the need for single-chip control
- Why is the IRQ pin of PN532 useless?