1. Principle Introduction
There is a full-duplex serial port inside the 51 single-chip microcomputer. What is a full-duplex serial port? Generally speaking, a serial port that can only receive or send is called a simplex serial port; a serial port that can both receive and send, but not at the same time, is called a half-duplex serial port; a serial port that can receive and send at the same time is called a full-duplex serial port. Serial communication refers to a communication method in which data is transmitted one bit at a time in sequence. Its outstanding advantage is that it only requires one transmission line, which can greatly reduce hardware costs and is suitable for long-distance communication. Its disadvantage is that the transmission speed is low.
As before, let's first understand the registers related to the microcontroller serial port.
SBUF register: It is two physically independent receiving and transmitting buffers, which can send and receive data at the same time. The operation on the receiving buffer or the transmitting buffer can be distinguished by reading and writing instructions on SBUF. Thus, two independent external receiving and transmitting signal lines RXD (P3.0) and TXD (P3.1) can be controlled to send and receive data at the same time, realizing full-duplex.
Serial port control register SCON (see Table 1).
Table 1 SCON register
The meanings of each bit in the table (from left to right, from high to low) are as follows.
SM0 and SM1: Serial port working mode control bits, their definitions are shown in Table 2.
Table 2 Serial port working mode control bits
Among them, fOSC is the clock frequency of the microcontroller ; the baud rate refers to the number of bits sent (or received) per second by the serial port.
SM2: Multi-machine communication control bit. This is only used for multi-machine communication in mode 2 and mode 3. The transmitter SM2 = 1 (program control setting is required). The serial port of the receiver works in mode 2 or 3. When SM2 = 1, only when the 9th data bit (RB8) is 1, the first 8 bits of data received are sent to SBUF, and RI is set to issue an interrupt request to trigger a serial reception interrupt, otherwise the received data will be abandoned. When SM2 = 0, regardless of whether the data bit is 0 or 1, the data will be sent to SBUF, and RI will be set to issue an interrupt request. When working in mode 0, SM2 must be 0.
REN: Serial receive enable bit: When REN = 0, reception is prohibited; when REN = 1, reception is allowed.
TB8: In modes 2 and 3, TB8 is the 9th bit of data to be sent by the transmitter. In multi-machine communication, it represents the address or data to be transmitted. When TB8=0, it is data, and when TB8=1, it is address.
RB8: In modes 2 and 3, RB8 is the 9th bit of data received by the receiver, which happens to come from TB8 of the transmitter, thereby identifying the characteristics of the received data.
TI: Serial port sends interrupt request flag. When the CPU has sent a serial data, the SBUF register is empty, and the hardware sets TI to 1 to request an interrupt. After the CPU responds to the interrupt, the software clears TI.
RI: Serial port receive interrupt request flag. When the serial port receives a frame of serial data, the SBUF register is full, and the hardware sets RI to 1 to request an interrupt. After the CPU responds to the interrupt, the software clears RI.
Power control register PCON (see Table 3).
Table 3 PCON register
The meanings of each bit in the table (from left to right, from high to low) are as follows.
SMOD: Baud rate doubling bit. SMOD=1, when the serial port works in mode 1, 2, or 3, the baud rate is doubled. SMOD=0, the baud rate remains unchanged.
GF1, GF0: general flag bits.
PD (PCON.1): Power-down mode bit. When PD=1, it enters power-down mode.
IDL (PCON.0): Standby mode bit. When IDL=1, enter the standby mode.
Other registers related to the serial port include the timer-related registers and interrupt registers described in the previous article. The timer register is used to set the baud rate. The ES bit in the interrupt enable register IE is also used as the serial I/O interrupt enable bit. When ES = 1, serial I/O interrupts are enabled; when ES = 0, serial I/O interrupts are disabled. The PS bit in the interrupt priority register IP is used as the serial I/O interrupt priority control bit. When PS = 1, it is set to high priority; when PS = 0, it is set to low priority.
Previous article:Using the 51 single-chip microcomputer's Pl port to realize independent keyboard control
Next article:Design of temperature control system based on 8051 single chip microcomputer
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
- Agilent6684A power supply maintenance method - Antai Instrument Maintenance
- Today is Arbor Day, happy holiday~~
- Learn electronics and Arduino from scratch: A beginner's guide to developing boards
- [NUCLEO-L452RE Review] +2.2-inch TFT display driver display
- C2000 CLA debugging and analysis
- [GD32L233C-START Review] 14. CAU encryption algorithm AES
- Setting the switching frequency of the switching power supply chip LTM4613
- Does the power layer of a four-layer board need to be made into a complete plane?
- [Register to enjoy gifts] element16 sincerely invites you to visit the 2019 Munich Shanghai Electronics Show
- E104-BT05 Test