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.
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
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- [GD32L233C-START Review] Running water lamp demo
- How to measure analog voltage using the ADC of MSP430?
- Isolated DAC output solution for analog signals
- 【BearPi-HM Nano, play Hongmeng "Touch and Pay"】-6-Code running doubts②
- Disassembling a ROG
- ADI New Chinese Information (November 2019)
- [GD32F310 Review] The board has not yet arrived, so we will distribute it first
- DSP system design - interference and board layout related issues
- Today at 10:00 am TI Award Live: Low-power wireless technology for building automation sensor applications
- For SMD components with thin pins, what should be the PCB wiring line width?