Introduction of single chip microcomputer serial port

Source: Internet
Author: User

Introduced

Serial port is a single-chip microcomputer and the external exchange of information tools, 8051 single -chip communication methods have two kinds:

Parallel communication: Data is sent or received at the same time. Serial communication: Data is sent or received in one order.

The way of serial communication

Asynchronous communication

    • With a starting bit 0 for the beginning of the character, with the stop bit 1 to indicate the end of the character, the middle of the 8 data bits, the character can be transmitted one after another
    • Both the CPU and the peripheral must have character format and baud rate provisions
    1. Character formatting rules allow both sides to interpret 0 and 1 strings in the same sense, in principle freely formulated, universal angle using standard such as ASCII
    2. Baud rate is the data transfer rate, the number of bits transmitted per second, such as 120 characters/s, 10 digits per character, the transmission baud rate is 1200 baud

Synchronous communication

The start end flag is removed to increase the speed, but because the data block delivery begins to be indicated by the synchronous character, and the synchronization between the sending and receiving ends is required by the clock, the hardware is more complicated.

Direction of communication

In serial communication, the one-way transmission that can only be sent or received by the communication interface is called a single-work transmission , and the two-way transmission of data is called Duplex transmission . Half-duplex transmission between the two machines can not be sent and received at the same time, can only send or receive information. A full-duplex transmission is able to send the receive at the same time.

Serial Interface Structure

    • 51 Single chip microcomputer a programmable full-duplex serial communication interface. Can be used as an asynchronous communication mode (UART), connected to an external device that transmits information serially. or 8,051 multi-machine systems for full duplex through synchronous or asynchronous standard communication protocols, use TTL or CMOS shift registers to expand I/O ports.
    • 8051 MCU communicates with the outside world through the pin RXD (P3.0, serial data receiving end) and pin TXD (P3.1, serial data sender). The SBUF is a serial port buffer register, which includes the transmit register and the receive register. They have the same name and address space, but there is no conflict because both of them can only be read by the CPU, and one can only be written by the CPU.
Control and status registers for serial ports

Serial Port Control Register SCON

Used to define how the serial port works and to implement receive and transmit control, byte address 98H

D7 D6 D5 D4 D3 D2 D1 D0
SM0 SM1 SM2 REN TB8 RB8 TI RI

SM0, SM1: Serial port working mode select bit

SM0, SM1 Working style Function description Baud rate
0 0 Mode 0 8-bit Shift register Fosc/12
0 1 Mode 1 10-bit UART Variable
1 0 Mode 2 11-bit UART FOSC/64 or FOSC/32
1 1 Mode 3 11-bit UART Variable

How the serial port works

Mode 0

    • Is the shift register input/output mode. An external shift register can be used to extend the I/O port, as well as external synchronous input/output devices. The 8-bit serial data is either input or output from the RXD, and the TXD is used to output the sync pulses.
    • Output: Terminal flag T1 Hardware set-up after sending. (with other)
    • Input: When ri = 0 and ren =1 simultaneously satisfy the start receive, the data is moved to the register after receiving the eighth bit, and the hardware is set to RI.

Mode 1

    • A 10-bit asynchronous communication mode with a variable baud rate.
    • Output: When an instruction is executed to write data to the send buffer sbuf, the send is initiated and a frame of hardware is sent out T1
    • Input: Detects 1-0 jumps, uses software to clear 0 Ri and SM2 before use

Mode 2

    • 11-bit UART mode for fixed baud rate. It adds a programmable 1 or 0 9th digit data than mode 1.
    • Output: 11-bit, additional nineth bit is the TB8 bit of Scon, which can be used as the address/data information marker bit and parity correction bit in multi-machine communication. Other with other
    • Input: 123 with

Mode 3

A 11-bit UART mode with a variable baud rate. The rest is the same as mode 2 except for the baud rate.

Baud Rate Selection

Mode 0: The baud rate of mode 0 is fixed to 1/12 of the main vibration frequency.

Mode 2: Baud rate is determined by smod bit in PCON

Baud Rate =2somd/64*fosc,smod=0 or 1

Modes 1 and 3:

Baud rate = Timer T1 overflow rate

T1 overflow rate = T1 count rate/number of cycles required to generate overflow

The T1 count rate depends on whether it works in the timer state or the counter state.

    • When working in the timer state, the T1 count rate is FOSC/12;
    • When working in the counter state, the T1 count rate is the external input frequency and this frequency should be less than fosc/24.

The period required to generate the overflow is related to the mode of operation of the timer T1 and the T1 preset value.

    • Timer T1 works on Mode 0: number of cycles required for overflow =8192-x
    • Timer T1 works on Mode 1: Number of cycles required for overflow =65536-x
    • Timer T1 works on Mode 2: Number of cycles required for overflow =256-x

Because Mode 2 is a 8-bit timer/Counter mode that automatically re-loads the initial value , it is most appropriate to use it to make a baud rate generator .

Single-chip microcomputer serial port introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.