Serial Communication of 8051 Microcontroller

Publisher:HarmonyJoyLatest update time:2019-05-13 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

There are two ways of computer data exchange: serial communication and parallel communication.


Parallel communication: Let's take 8 bits (one byte) of data as an example. Under parallel communication, 8 bits of data are transmitted at the same time, sent and received at the same time. Therefore, both parties in communication need a common clock signal. Parallel transmission is fast and efficient. However, it requires more data lines and a shorter transmission distance.


Serial communication: Still taking 8-bit data as an example, each bit of data is sent in time-sharing, and the receiver also receives it one bit at a time. Serial communication only requires one data line, which is low-cost. It is suitable for large-scale and long-distance data transmission.


Asynchronous transfer mode: Each transmitted character is wrapped with a start bit and a stop bit, and gaps of varying lengths are allowed between characters.


Synchronous transmission mode: A data block contains many consecutive characters, with no idle time between characters. Synchronous transmission can easily implement the format required by a certain communication protocol.


Baud rate: Here it is defined as the number of "bits" transmitted per second in serial communication. That is, n baud = nb/s. In the RS-232C standard, the baud rate of serial communication is specified as follows: 600, 1200, 2400, 4800, 9600, etc.


Calculation of the baud rate of the serial port:


In mode 0, the baud rate is fixed at: F/12 (F is the crystal frequency)


In mode 2, the baud rate is fixed to: F/32 or F/64 (depending on the SMOD bit of the PCON register, if SMOD = 1, it is F/32; otherwise it is F/64).


Mode 1 and Mode 3: The overflow rate of the T1 timer is used as the baud rate generator, so the calculation formula is:


                                K*F/[32*12*(2^n - X)].


If SMOD = 1, then K = 2, otherwise K = 1, F is the crystal frequency, n is the number of bits in the timer (that is, which working mode the timer is in), and X is the initial value filled by the timer.


In serial communication, both parties are required to have the same baud rate, but sometimes we cannot reach that baud rate accurately. At this time, we need to consider which of the two cases, SMOD = 1 and SMOD = 0, produces a smaller relative error, and we will choose that one.


Relative error = (actual value - theoretical value) / theoretical value * 100%

Reference address:Serial Communication of 8051 Microcontroller

Previous article:Memory expansion of 51 single chip microcomputer
Next article:8051 MCU External Interrupt Programming Example

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号