General methods and steps for realizing communication between PC and 51 series single chip microcomputer

Publisher:ikfnpoLatest update time:2017-12-26 Source: eefocusKeywords:PC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    With the continuous development of single-chip microcomputer and microcomputer technology, especially the widespread application of network technology in the field of measurement and control, the multi-machine network measurement and control system composed of PC and multiple single-chip microcomputers has become a direction of single-chip microcomputer technology development. It combines the advantages of single-chip microcomputer in real-time data acquisition and microcomputer in graphics processing and display. At the same time, the background microcomputer in Windows environment has obvious advantages in database management. The combination of the two makes the application of single-chip microcomputer not only limited to automatic monitoring or control in the traditional sense, but also forms a trend of development towards a distributed multi-point system with network as the core. This article mainly introduces the general methods and steps for PC and 51 series single-chip microcomputer to achieve communication.

 

    Hardware structure and single chip computer programming

    The serial communication between the microcontroller and the PC generally adopts the standard interface of RS-232, RS-422 or B3-485 bus, and some adopt the non-standard 20nnJL current loop. To ensure the reliability of communication, the following must be considered when selecting the interface: (1) communication rate; (2) communication distance; (3) anti-interference ability; (4) networking mode. This article mainly introduces the method of using RS-232 interface to communicate with the microcontroller.

    1. RS-232 level conversion and PC interface circuit

   76

    RS-232 is an early standard for public telephone network data communication. Its logic level is completely different from ITL CMOS . Logic "0" is specified as between +5 and +15V, and logic "1" is specified as between -5 and -15V. Since there is a common ground between RS-232 sending and receiving, and the transmission adopts unbalanced mode, common mode noise will be coupled into the signal system. The maximum communication distance recommended by the standard is 15 meters. But in actual application, we can reach 300 meters at a rate of 300bi:/s.

   32

    The levels specified by RS-232 are inconsistent with the logic levels of general microprocessors , so level conversion must be performed. The following three methods can be used to achieve logic level conversion.

    The conversion interface using MCl488 and MCl489 chips MCl488 and MCl489 chips are early RS-232 to TTL logic level conversion chips. The figure above shows the actual circuit. The inconvenience of this circuit is that it requires ±12V voltage and consumes a lot of power, which is not suitable for low-power systems. In the figure, TXD and RXD are connected to the sending and receiving ends of the microcontroller respectively.

    The conversion interface using MAX232 chip MAX232 is produced by MAXIM, and contains two-way drivers and receivers of RS-232 conversion chip. The above figure is the actual circuit. There is a voltage converter inside the chip, which can convert the input +5v voltage into the ±10V voltage required by the RS-232 interface, especially suitable for single power supply systems without ±12V. Other chips with the same principle include MAX202, AD's ADDtl01 and INl2 SIL 's IC l232 chips.

    The above figure shows the RS-232-TTL level conversion interface circuit implemented by discrete components. Its characteristic is that the 3rd pin signal output (4th and 7th pins can also be used) of the BS-232 interface of the PC is used to supply the negative power supply. The 3rd, 4th and 7th pins of the FC machine are all 1 level (about -10V) when the logic "0" level is not sent, and its driving capacity is 20mA. Using this characteristic, a diode and an electrolytic capacitor are used , that is, the negative power supply required for RS-232 communication is obtained on the electrolytic capacitor . The circuit is simple and has low power consumption. It is an alternative method when there is no dedicated chip.

    The RS232 to TTL level conversion method introduced above can be applied to most communication systems. In some special applications where electrostatic protection or multiple transceivers (such as connecting to a MODEM) are required, chips such as MAX238 (4 drivers, 4 receivers) or MAX3221t (15Kv electrostatic protection) can be used.

    2. Single chip microcomputer communication program design

    MCU serial working mode The serial communication of the 51 series MCU, which is widely used at present, can work in synchronous or asynchronous mode. Most 51 series MCUs compatible with 8031 ​​have one or more UART  asynchronous serial interfaces, which provides a good convenience for users to design communication programs. When multiple serial communication interfaces are required in the application system, the following methods can be used: (1) Use a MCU with multiple serial ports, such as Winbond's WW77E58, which has two serial interfaces; (2) Use a universal asynchronous serial port expansion chip, such as TLl6c552 (2-way) and LCl6C554 (4-way); (3) Use ordinary I/O simulation to achieve communication. This is the simplest and most economical method, and it can achieve high-speed serial communication. This article only discusses the design method of using an asynchronous serial communication. The control method of the MCU serial port The control of the serial port of the MCS-51 series MCU is achieved by setting the serial port control register SCON and the power control register PCON. SCON is a bit-addressable special function register. By setting SM0 and SMI of SGON, the MCU can have four different working modes. The format of SCON can be found in the relevant manual. When used to achieve serial communication with a PC, it is generally set to mode 1 or mode 3. The main difference is that the data format of mode 1 is 8 bits, and the data format of mode 3 is 9 bits, of which the 9th bit SM2 is the multi-machine communication bit, which can achieve multi-point communication of the microcontroller. The SMOD of the power control register PCON is the serial port baud rate control bit. When the microcontroller's bit vibration is an integer (such as 6M), setting 5MOD to 1 can usually obtain a higher communication speed, but SMOD cannot be bit-addressed.

    When the microcontroller communicates with the PC, the communication rate is generated by timer T1 or timer T2 (52 series). When T1 works in mode 2, the communication rate is calculated as follows: baud string = (SMOD × Fosc) / (32 × 12 × [256-TH1]). Among them, the Fosc crystal frequency is usually 11.0592MH2 to obtain an accurate communication rate. The rate of the system using the T1 timer communication cannot be too high. Generally, the maximum rate is 19200bit/s. For example, in order to obtain a higher communication rate, the timer T2 of the 52 series microcontroller can be used, and the maximum rate can reach 115200bjt/s. In actual applications, we have achieved a high-speed communication of 38400bit/s in a microcontroller system with a 6MH2 crystal oscillator.

    Implementation method of single-chip microcomputer serial communication program In actual application, single-chip microcomputer communication program generally uses interrupt mode to communicate with microcomputer, and microcomputer is the main control party. When the single-chip microcomputer receives the address signal sent by the microcomputer, it will enter the interrupt service program and send data to the microcomputer. The interrupt service program flow is shown in Figure 4. The interrupt service program is also applicable to multi-machine communication systems. For a detailed program list, please refer to the website COMMON.ASM of this magazine. The crystal oscillator of the single-chip microcomputer is 11. 0592M Hz , the communication rate is 9600bit/s, and the frame format is N.8.1.


Keywords:PC Reference address:General methods and steps for realizing communication between PC and 51 series single chip microcomputer

Previous article:Design of temperature control system based on 8051 single chip microcomputer
Next article:Application of X25165 in 8051 MCU System

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号