Realization of serial communication between PIC microcontroller and PC

Publisher:HarmoniousVibesLatest update time:2013-05-16 Source: 电子设计工程 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
    With the development of single-chip microcomputer technology, PIC single-chip microcomputers are increasingly used in industrial control systems to monitor and control parameters such as temperature, pressure and flow. PCs have powerful monitoring and management functions, while single-chip microcomputers have fast and flexible control characteristics. Communicating with external devices through the RS-232 serial interface of PCs is a common communication solution in many measurement and control systems. It not only utilizes the real-time control characteristics of single-chip microcomputers, but also gives full play to the advantages of strong computing power and large storage capacity of PCs. In daily applications, a large amount of data calculation is usually required, but the computing power of PIC single-chip microcomputers is limited, and the data processing power of PCs must be used. Therefore, it is particularly important to achieve reliable data transmission between PIC single-chip microcomputers and PCs. In this
    article, the synchronous/asynchronous serial module (USART) of PIC single-chip microcomputers will be used to communicate with computers via serial ports. The communication software of the PC is written in Visual C++6.0, and specifically uses the MSComm control to complete the communication with the PIC single-chip microcomputer.

1 Concept of asynchronous serial communication
    The asynchronous serial communication between the PIC single-chip microcomputer and the PC is realized by RS-232 serial interface circuit, and the serial interface of the PC is used for data transmission. In asynchronous communication, data is transmitted frame by frame, and its format is shown in Figure 1.

g.JPG


    In the frame format, a character consists of 4 parts: start bit, data bit, parity bit and stop bit. First is a start bit "0", then 5 to 8 bits of data, followed by a parity bit, and finally a stop bit "1". The start bit "0" signal only occupies 1 bit and is used to notify the receiving device that a character to be received has begun to arrive. When no character is transmitted, the line should remain at "1". The receiving end continuously detects the state of the line. If a "0" is detected after a continuous "1", it knows that a new character is to be sent and should be prepared to receive immediately.

2 Introduction to interface devices
2.1 Level conversion chip
   
The PC and HC microcontroller communicate using the RS-232 serial bus standard. The typical RS-232 signal swings between positive and negative levels. When sending data, the transmitter driver outputs a positive level voltage range of 5 to 15 V and a negative level of -15 to -5 V. When there is no data transmission, the line is TTL level. From the beginning of data transmission to the end, the line level changes from TTL level to RS-232 level and then returns to TTL level. The typical working level of the receiver is between 3~12 V and -12~-3 V. Such a high voltage cannot be directly connected to the microcontroller, so a level conversion must be performed. In this paper, MAX232 is used to achieve level conversion. The MAX232 chip is a chip compatible with the RS-232 standard launched by Texas Instruments . The device contains 2 drivers, 2 receivers and a voltage generator circuit to provide TTA/EIA-232-F level.
2.2 Introduction to signal interface
   
PCs have serial interfaces, generally using RS-232 interfaces. The connectors that match RS-232 are DB-25, DB-15 and DB-9, and their pins are also different. The DB-9 connector is used in this paper as a connector that provides two serial interfaces COM1 and COM2 on the I/O card or motherboard, providing 9 signals for asynchronous communication.

3 Hardware circuit design
3.1 Schematic diagram of serial communication between PC and PIG microcontroller The
    serial communication principle between PC and PIC microcontroller is shown in Figure 2. The whole system consists of 3 parts. Since the serial communication between PC and PIC microcontroller adopts RS-232 protocol, whether the microcontroller sends data to PC or PC sends data to microcontroller, the level conversion must be performed through MAX232. When the circuit is connected, the serial port output of PC should correspond to the serial port input of PIC microcontroller.

a.JPG[page]

3.2 System Circuit Connection Diagram
   
The entire system circuit connection diagram can be divided into two parts, the connection between the PIC microcontroller serial port and MAX232, and the connection between MAX232 and the PC serial port through the DB-9 connector, as shown in Figure 3. Connect the "RC6/TXD" pin of the PIC microcontroller to the "T1IN" pin of the MAX232; connect the "RC7/RXD" pin of the microcontroller to the "R1OUT" pin of the MAX232, that is, connect the input pin of the microcontroller to the output pin of the MAX232; connect the output pin of the microcontroller to the input pin of the MAX232.

b.JPG


    MAX232 is connected to the serial port of the PC through a DB-9 connector. The specific implementation should use a standard serial port line to connect AX232 to the COM1 port of the PC.

4 Program Design
   
The entire program design is divided into two parts, namely the communication program of the PC and the communication program of the PIC microcontroller. Since the communication program of the PIC microcontroller is written in assembly language, its writing process is similar in various environments.
    There are three ways to implement serial communication in VC, using the MSComm control or the CSerialPont class for serial communication, and the WinAPI function can also be used to operate the serial port. The following focuses on the method of using the MSComm control to implement serial communication in the Visual C++6.0 development environment.
    The programming adopts a dialog-based main program framework structure, and the serial communication part is completed using the MSComm control. The specific steps are as follows.
    (1) Create a project. Open the Vlsaal C++6.0 programming environment, create a new project, and enter the corresponding project name and the path where the project is located.
    (2) Add corresponding resources. In order to operate the program in a friendly interface, the corresponding resources must be added to the application. In this article, only the necessary controls for the communication program are added. Add two "EDIT" controls; one is used to input the data sent to the microcontroller; the other is used to display the data received from the microcontroller. Add a "Send" button to determine when to send. The serial communication in this article is completed through the MSComm control, so the MSComm control needs to be added. After adding the MSComm control, it is necessary to set it accordingly. The setting of the MSComm control must be set according to the reasonable parameters of the microcontroller outside the computer, otherwise normal serial communication cannot be guaranteed. The setting interface of the MSComm control in this article is shown in Figure 4.

c.JPG

[page]

    (3) Add member variables. The controls on the application are responsible for receiving input or displaying output. The member variables in the application background manage these data. After adding resources, the controls and member variables must be associated. The member variable adding interface is shown in Figure 5.

d.JPG


    (4) Message mapping. When the microcontroller sends data to the PC through the serial port or clicks the "Send" button, Windows messages are triggered and the application window will receive these messages. After receiving the message, check whether the application processes these message functions. To process these functions, corresponding message mappings must be added.
    (5) Add program execution code. The program flow of the Visual C++ program on the PC is shown in Figure 6.

e.JPG


    After adding the message map, only a framework of the function that processes these messages is given, and the specific processing code must be added by the user.
    After compiling, the application running result on the PC is shown in Figure 7.

f.JPG


    Write the data to be sent into the send number control, click the "Send" button, and the PC will send the data to the microcontroller through the serial port. If the microcontroller sends data to the PC, the program will automatically display the received data in the receiving number control.

5 Conclusion
    The serial communication between PIC microcontroller and PC is widely used in various control systems. This article proposes a method to realize the serial communication, and gives a specific circuit schematic and communication program. Practice has proved that the use of VC to develop a communication system is directly user-oriented from the bottom layer to the upper layer, and has a strong debugging function. Therefore, this article provides a good reference for the implementation of serial communication between PC and PIC microcontroller.

Reference address:Realization of serial communication between PIC microcontroller and PC

Previous article:Design of kitchen controller based on PIC microcontroller
Next article:Small problems encountered by PIC microcontroller when continuously receiving serial port data

Recommended ReadingLatest update time:2024-11-16 19:41

Realizing Serial Communication between PC and AT89C51 Microcontroller under Windows
In the data acquisition and real-time control system based on the single-chip microcomputer, the command and data transmission between the computer and the single-chip microcomputer is carried out through the RS-232 interface in the computer, and the computer can be used to monitor and control the production site. S
[Microcontroller]
Design of Universal Automatic Test System Based on PC104
The universal automatic test system platform can save testing costs to the greatest extent, including software development costs, system maintenance and upgrade costs, and new test system development costs. The test program set TPS is portable, so that a set of programs can be developed to suit a variety of dif
[Test Measurement]
Design of Universal Automatic Test System Based on PC104
Serial Communication between PC and MCU under Windows CE.NET 4.2
In industrial control, it is often necessary to transmit the data collected by the microcontroller to the PC for processing and display, and send control commands to the microcontroller based on the processing results. Although serial communication has a relatively slow transmission speed, it has a low transmission
[Microcontroller]
Intel CEO Pat Gelsinger: Building x86 core architecture to promote AI PC innovation
AI is "entering ordinary people's homes" and becoming a productivity and creative tool that can be used anytime and anywhere, making our daily lives better. Behind the rapid technological progress are chips with stronger performance, lower power consumption, and better adaptability to AI workloads, pr
[Network Communication]
Intel CEO Pat Gelsinger: Building x86 core architecture to promote AI PC innovation
Design of Communication between PIC Microcontroller and PC
1. PC programming PC is written in Toubr C. The program is as follows: #include #define port 0x3f8 /*Use serial port 1 for communication*/ int ch[15]; main () { int a; int i,j; int b[6]={88,15,38,26,20,0}; char c; cl rs cr(); outportb(port 3, 0x80); /* prepare to set baud rate */ outportb(port,0x0C); /*Set the baud
[Microcontroller]
Design of Communication between PIC Microcontroller and PC
Boréas BOS1921 meets the needs of ultra-thin PC touch panels for high-performance, low-cost tactile functions
Boréas BOS1921 meets the needs of ultra-thin PC touch panels for high-performance, low-cost tactile functions Piezo haptic drivers save BOM cost and hardware footprint while improving responsiveness and resolution Bromont, Quebec, Canada - September 29, 2022 - Boréas Technologies introduces the BOS1921, a micro pi
[Internet of Things]
Boréas BOS1921 meets the needs of ultra-thin PC touch panels for high-performance, low-cost tactile functions
Using VB 6.0 to realize the communication between network remote PC and single chip microcomputer
In the design of various single-chip microcomputer application systems, the communication problem between single-chip microcomputer and PC is often encountered. In the occasions where the speed requirement is not high and the transmission distance is not far, the RS 232 standard serial interface is generally used. I
[Microcontroller]
Using VB 6.0 to realize the communication between network remote PC and single chip microcomputer
[nrf51][nrf52][Three-party communication] PC/mobile phone MCU BLE communication template is for reference only
According to the principle of serial communication, the interactive communication environment between the three parties is designed and built, and data is sent and received to each other through the protocol. The module is implemented. The design realizes the interactive communication mode of the three parties, and th
[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号