Principle example of 51 single chip microcomputer serial communication

Publisher:RadiantGazeLatest update time:2017-12-26 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    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

     

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

     

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

     

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.


Reference address:Principle example of 51 single chip microcomputer serial communication

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

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号