Principles of Single-Chip Microcomputers P4: 80C51 Serial Port and Serial Bus Extension

Publisher:温柔微笑Latest update time:2024-08-21 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

0. Serial communication


0. Data transmission mode of serial communication: simplex (one-way data transmission), half-duplex (non-simultaneous two-way transmission), full-duplex (simultaneous, two-way transmission)

1. According to the different communication methods, it is divided into synchronous communication and asynchronous communication.

Synchronous communication: All devices use the same clock, called the synchronous clock. When transmitting data, it is transmitted in units of several data characters (called data blocks). Each data block includes a synchronization character, a data block, and a check character CRC.

Asynchronous communication means that in serial communication, the receiving device and the sending device have their own clock signals. Asynchronous communication transmits data in characters, but the clock frequencies must remain consistent during communication.

2. Baud rate and bit rate

The baud rate is the amount of signals transmitted per second (unit: baud B), and the bit rate is the amount of signals transmitted per second (unit: bps). In the microcontroller, these two things are the same.

For example, if the data transmission rate of both parties is 240 characters per second, and each character contains 10 bits (1 start bit, 8 data bits, and 1 stop bit), then the baud rate is

240 × 10 = 2400b/s = 2400B

3. SCON (98H, bit addressable)

SM0 and SM1 are used to set the serial port working mode.

SM2 is set to send address or data when the serial port works in mode 2 or 3.

REN is the acceptance permission bit, and TB8 is the value of the ninth programmable bit in working modes 2 and 3.

TI is the transmit flag.

RI is the receive flag.

4. PCON (87H, not bit addressable)

The highest bit can be used to adjust the baud rate, and the lower bits are related to power management.

80C51 serial port working mode: (P3.0 is the displacement input RxD (low bit first), P3.1 is the displacement output TxD)

Working mode 0: (Synchronous) 8 bits of data are one frame, there is no stop bit and start bit, the condition for sending the serial port is TI = 0; the condition for receiving is RI = 0 and REN = 1 (allow acceptance bit).

The baud rate is fixed at fosc/12. RB8 is not used.

Working mode 1: (asynchronous) (used for dual-machine communication) 10 bits of data form a frame, the lowest bit is the start bit (0), and the highest bit is the stop bit (1). SM2 = 0, RB8 receives the stop bit. In fact, when sending, working mode 1 continuously shifts the data to the right to the TxD port (the highest bit is already set to 1), and then continuously fills 0 on the left, and TI = 1 after sending; when receiving, it is just the opposite. When receiving, it will fill 1 at the receiving port. Once a jump from 1-0 is found (the start bit is received), it starts to receive data until the received stop bit is 1, which means the received information is correct. Then RI = 1.

Working modes 2, 3: (asynchronous) (multi-machine communication), 11 bits of data per frame, in addition to the start bit and stop bit, it also includes a programmable bit. This bit is provided by TB8 of SCON and can be used for parity check. It can also be combined with SM2 for multi-machine communication. TB8 is set when sending and RB8 when receiving.

When SM2 = 0, data and address are accepted; when SM2 = 1, only address is accepted (reflected in that the RB8 bit of the received information must be 1 (indicating that it is an address))

Serial port baud rate calculation:

The baud rate of mode 0 is 1/12 of the crystal frequency.

The baud rate of mode 2 is: baud rate = (2SMOD/64) × fosc

The baud rate of mode 1 and mode 3 = (2SMOD / 32) × timer overflow rate (usually mode 2 is selected as the clock for mode 1 and mode 3)

Common baud rates (get familiar with them):

Serial communication programming example (note that you need to manually clear TI and RI)

(send)


MOV R0, #40H; Set the initial value of the data block address pointer

MOV R7, #10H; Set the initial value of the data block length

ALOOP3: MOV SBUF, @R0; send a data byte

JNB TI, $; Waiting for sending to complete

CLR TI ; Clear send flag

INC R0;Address unit plus 1

DJNZ R7, ALOOP3; Whether the entire data block has been sent


(take over)


MOV R0, #40H; Set the initial value of the data block address pointer

MOV R7, #10H; Set the initial value of the data block length

BLOOP3: JNZ RI, $; Waiting to receive information

CLR RI ; Clear the receive flag

MOX A, SBUF; read the contents of the receive buffer

MOX @R0, A; receive data dump

INC R0; storage unit plus 1

DJNZ R7, BLOOP3; Determine whether the data block has been received


In the master-slave multi-machine communication system composed of MCS-51, there is only one master machine and a maximum of 256 slave machines.

1. I^2C bus

The encoding content includes: device identification, pin level, and direction bit.

Two lines: SCL (clock line), SDA (data line), 9-bit data transmission format (the last acknowledge bit).

When SCL is high, the falling edge of SDA indicates start.

When SCL is high, the rising edge of SDA indicates stop.


Reference address:Principles of Single-Chip Microcomputers P4: 80C51 Serial Port and Serial Bus Extension

Previous article:Principles of Single-Chip Microcomputers P3: 80C51 External Expansion System
Next article:Principles of Single-Chip Microcomputers P2: 80C51 External Interrupts and Timer Systems

Recommended ReadingLatest update time:2024-11-16 09:37

80c51 pin diagram pin diagram and introduction to each pin function
80c51 pin diagram pin diagram and introduction to each pin function Vss(20 pin): ground VCC (pin 40): main power supply +5V XTAL1 (pin 19): Connect one end of the external crystal. On-chip it is the input terminal of the inverting amplifier of the oscillation circuit. When using an external clock, for HMOS micr
[Microcontroller]
80c51 pin diagram pin diagram and introduction to each pin function
80C51 learning water lamp
/* Common preprocessing commands in C language 1. Use of #define No semicolon is needed after #define A PO. #define PI 3.14 2. Circular left and right shift functions _crol_(a,b) is a circular left shift function, where a is the value to be shifted left and b i
[Microcontroller]
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号