Course Design of Serial Communication between Single Chip Microcomputer and PC

Publisher:星尘之泪Latest update time:2020-01-09 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1.1 Design Purpose

The serial communication port between the microcontroller and the PC has always occupied an extremely important position in the scope of system control. It has not been eliminated due to the progress of the times, but has become more and more perfect in specifications and more and more widely used. As a basic, flexible and convenient communication method, serial communication is widely used in data exchange between PC and PC or PC and microcontroller and other industrial control and automatic control. Nowadays, in many occasions, the microcontroller is required not only to independently complete the control task of a single machine, but also to exchange data with other data control devices (microcontroller, PC, etc.). Therefore, how to realize the communication between PC and microcontroller has very important practical significance.


1.2 Design content

With the single-chip microcomputer and PC as the core, serial port communication between the single-chip microcomputer and PC is realized.


2 System Hardware Circuit Design

2.1 System Design Block Diagram

Figure 2-1 System design block diagram


2.2 Basic principles of serial communication

The so-called "serial communication" refers to the use of a data signal line between the peripheral and the computer. Data is transmitted bit by bit on a data signal line, and each bit of data occupies a fixed length of time. This communication method uses fewer data lines, which can save communication costs in long-distance communication. Of course, its transmission speed is slower than parallel transmission. In contrast, due to the requirement of high speed, the communication between the CPU and the serial port inside the computer still uses parallel communication. Therefore, the essence of the serial port is to realize the data format conversion between the CPU and the peripheral data device (or called a serial-to-parallel converter), that is, when data is input from the peripheral device to the computer, the data format is converted from bit to byte data; conversely, when the computer sends downlink data to the peripheral device, the serial port converts the byte data into bit data.


The essential function of the serial port is to act as a code converter between the CPU and the serial device. When data is sent from the CPU through the serial port, the byte data is converted into serial bits. When receiving data, the serial bits are converted into byte data.

In Windows environment (Windows NT, Win98, Windows2000), serial port is part of system resources. If an application wants to use serial port for communication, it must submit resource request to the operating system before use (open serial port), and must release resources (close serial port) after communication is completed.

The concept of serial communication is very simple. Serial ports send and receive bytes by bit. Although slower than parallel communication by byte, serial ports can send data on one line while receiving data on another line. It is simple and can achieve long-distance communication. For example, when IEEE488 defined the parallel communication state, it stipulated that the total length of the device line should not exceed 20 meters, and the length between any two devices should not exceed 2 meters; for serial ports, the length can reach 1200 meters.


Typical serial ports are used to transmit ASCII characters.

Communication is accomplished using three wires: (1) ground, (2) transmit, and (3) receive. Since serial communication is asynchronous, a port can send data on one wire while receiving data on another. The other wires are used for handshaking but are not required. The most important parameters for serial communication are the baud rate, data bits, stop bits, and parity. For two ports to communicate, these parameters must match:


a. Baud rate: This is a parameter that measures the speed of communication. It indicates the number of bits transmitted per second. For example, 300 baud means 300 bits are sent per second. When we mention the clock cycle, we are referring to the baud rate. For example, if the protocol requires a 4800 baud rate, then the clock is 4800Hz. This means that the sampling rate of the serial communication on the data line is 4800Hz. Common baud rates for telephone lines are 14400, 28800 and 36600. The baud rate can be much larger than these values, but the baud rate is inversely proportional to the distance. High baud rates are often used for communication between instruments that are placed very close to each other. A typical example is the communication between GPIB devices. 

b. Data bits: This is a parameter that measures the actual data bits in communication. When a computer sends a packet of information, the actual data will not be 8 bits. The standard values ​​are 5, 7, and 8 bits. How to set it depends on the information you want to transmit. For example, the standard ASCII code is 0 to 127 (7 bits). The extended ASCII code is 0 to 255 (8 bits). If the data uses simple text (standard ASCII code), then each data packet uses 7 bits of data. Each packet refers to a byte, including start/stop bits, data bits, and parity bits. Since the actual data bits depend on the choice of communication protocol, the term "packet" refers to any communication situation. 

c. Stop bit: used to indicate the last bit of a single packet. Typical values ​​are 1, 1.5 and 2 bits. Since data is timed on the transmission line and each device has its own clock, it is likely that there will be a small desynchronization between the two devices during communication. Therefore, the stop bit not only indicates the end of the transmission, but also provides an opportunity for the computer to correct the clock synchronization. The more bits are applied to the stop bit, the greater the tolerance for different clock synchronization, but the data transmission rate is also slower. 

d. Parity bit: A simple error detection method in serial communication. There are four error detection methods: even, odd, high and low. Of course, no parity bit is also possible. For even and odd parity, the serial port will set the parity bit (the bit after the data bit) with a value to ensure that the transmitted data has an even or odd number of logical high bits. For example, if the data is 011, then for even parity, the parity bit is 0, ensuring that the number of logical high bits is an even number. If it is odd parity, the parity bit is 1, so there are 3 logical high bits. The high and low bits do not actually check the data, and simply set the logic high or logic low check. This allows the receiving device to know the state of a bit and have the opportunity to determine whether noise interferes with communication or whether the transmission and reception of data are not synchronized.


2.3 Introduction to AT89C51 Microcontroller

AT89C51 is a low voltage, high performance CMOS 8-bit microprocessor with 4K bytes of flash programmable and erasable read-only memory, commonly known as a single-chip microcomputer. This device provides a highly flexible and inexpensive solution for many embedded control systems. Its pin functions are as follows:

VCC: power supply voltage.

GND: Ground.

P0 port: P0 port is an 8-bit open-drain bidirectional I/O port, each pin can absorb 8TTL gate current. When the pin of P0 port is written as 1 for the first time, it is defined as a high-impedance input. P0 can be used for external program data storage, and it can be defined as the lower eight bits of data/address. When programming FIASH, P0 port is used as the original code input port. When FIASH is verified, P0 outputs the original code. At this time, a pull-up resistor must be connected to the outside of P0.


P1 port: P1 port is an 8-bit bidirectional I/O port with an internal pull-up resistor. The P1 port buffer can receive and output 4TTL gate current. After the P1 port pin is written to 1, it is internally pulled up to high and can be used as an input. When the P1 port is externally pulled down to a low level, it will output current. This is due to the internal pull-up. During FLASH programming and verification, the P1 port is received as the lower eight-bit address.

P2 port: P2 port is an 8-bit bidirectional I/O port with an internal pull-up resistor. The P2 port buffer can receive and output 4 TTL gate currents. When the P2 port is written "1", its pin is pulled high by the internal pull-up resistor and used as input. And therefore, when used as input, the pin of the P2 port is pulled low externally and outputs current. This is due to the internal pull-up. When the P2 port is used to access the external program memory or the 16-bit address external data memory, the P2 port outputs the upper eight bits of the address. When the address "1" is given, it takes advantage of the internal pull-up. When reading and writing the external eight-bit address data memory, the P2 port outputs the contents of its special function register. The P2 port receives the upper eight-bit address signal and control signal during FLASH programming and verification.


P3 port: P3 port pins are 8 bidirectional I/O ports with internal pull-up resistors, which can receive and output 4 TTL gate currents. When "1" is written to P3 port, they are internally pulled up to a high level and used as input. As input, due to the external pull-down to a low level, P3 port will output current (ILL) due to the pull-up.

P3.0 RXD (serial input port)

P3.1 TXD (serial output port)

P3.2 /INT0 (external interrupt 0)

P3.3 /INT1 (external interrupt 1)

P3.4 T0 (Timer 0 external input)

P3.5 T1 (Timer 1 external input)

P3.6 /WR (External data memory write strobe)

P3.7 /RD (external data memory read strobe)


Figure 2-2 ATC89C51 pin diagram


2.4 9-pin serial port

9-pin serial port: A complete RS-232 interface is a 25-pin D-type plug. The 25-pin connector actually has only 9 connecting wires, so a simplified 9-pin D-type RS-232 plug is created. The most commonly used one is a 9-pin D-type plug.


EIA-RS-232C stipulates the electrical characteristics, logic levels and various signal line functions:
On TxD and RxD: Logic 1 (MARK) = -3V ~ -15V 
Logic 0 (SPACE) = +3 ~ +15V 
On control lines such as RTS, CTS, DSR, DTR and DCD: 
Signal valid (connected, ON state, positive voltage) = +3V ~ +15V 
Signal invalid (disconnected, OFF state, negative voltage) = -3V ~ -15V 
Voltages between -3 and +3V are meaningless, and voltages below -15V or above +15V are also considered meaningless. Therefore, if communication is to be carried out, the signal level must be converted, such as using the MAX3232 chip to convert the level. When using the serial port for communication, we are most concerned about the following three pins: 5 GND, 2 RXD, 3 TXD To complete the sending and receiving of data, you must reach the above three pins. The other pins are used to control the transmission rules, that is, the handshake protocol. Below is the 9-pin serial port (DB9) and the pin functions.

[1] [2]
Keywords:MCU Reference address:Course Design of Serial Communication between Single Chip Microcomputer and PC

Previous article:Design of ADC0808 digital voltmeter based on 51 single chip microcomputer
Next article:16*16 dot matrix Chinese character display simulation plus source code using 74hc595 driver chip

Recommended ReadingLatest update time:2024-11-15 16:17

Advantages of PIC series microcontroller applications
1. The biggest feature of the PIC series of microcontrollers is that they do not simply pile up functions, but start from reality, pay attention to the performance and price ratio of products, and develop multiple models to meet different levels of application requirements. In reality, different applications have diffe
[Microcontroller]
at89s52 microcontroller pin diagram, at89s52 pin description
  This article introduces you to the at89s52 microcontroller pin diagram and pin description, at89S52 features and functions. at89S52, a high-performance 8-bit microcontroller.   AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller. It contains 8k Bytes ISP (In-system programmable) Flash read-only pro
[Microcontroller]
at89s52 microcontroller pin diagram, at89s52 pin description
51 single chip microcomputer LED dot matrix breathing light effect
STC 89C52RC #include  reg52.h       typedef unsigned char uchar;   typedef unsigned int uint;   typedef unsigned long ulong;      sbit ADDR0 = P1^0;   sbit ADDR1 = P1^1;   sbit ADDR2 = P1^2;   sbit ADDR3 = P1^3;   sbit ENLED = P1^4;      ulong periodCnt = 0; //PWM period count value   uchar highRH = 0;
[Microcontroller]
PIC microcontroller CCS C language (application of #INT_DEFAULT)
#INT_DEFAULT Syntax: #int_default Purpose: If the PIC triggers an interrupt and no interrupt flag is set, the following function will be called. If there is an interrupt flag, but it is never triggered, the #int_default function will also be called. Example: #int_default default_isr(){ printf(“Unexplained inte
[Microcontroller]
Experiment 3: Table Lookup, Multi-branch (80C51 MCU Assembly Language Programming)
Suppose there is a table with the numbers: 00H, 11H, 22H...FFH. Put the lower 4 bits of the 00H unit on the chip into the 0000H outside the chip (the upper 4 bits of 0000H are 0), and put the upper 4 bits into the 0001H outside the chip (the upper 4 bits of 0001H are 0). According to the number in 0000H, take out the c
[Microcontroller]
One of the solutions to the problem of Atmega16 microcontroller entering "Programming mode failure"
I've been working on an ATmega16 microcontroller recently. I made a PCB board myself. At first, I was able to download programs, but after downloading a few times, I suddenly couldn't download them. Every time, it prompted "Failed to enter programming mode", as shown below There are also the following tips, which ro
[Microcontroller]
One of the solutions to the problem of Atmega16 microcontroller entering
Design of parameter tester for solar power generation system using AT89S52 microcontroller
introduction In order to ensure that the solar power generation system can work normally, it is necessary to measure various environmental parameters of the solar power generation system to effectively control its operation. This article introduces a solar parameter tester based on a single-chip microcomputer, which p
[Microcontroller]
Design of parameter tester for solar power generation system using AT89S52 microcontroller
Discussion on Low Power Consumption of PIC Microcontroller
Many people say that one of the biggest advantages of PIC microcontrollers is their low power consumption. Let’s discuss how to achieve low power consumption. 1. Sleep Sleep mode is one of the most common ways to reduce power consumption, but the microcontroller cannot do anything during sleep. For those who fall
[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号