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.
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.
[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.
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.
[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.
(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.
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.
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.
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
- Popular Resources
- Popular amplifiers
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Virtualization Technology Practice Guide - High-efficiency and low-cost solutions for small and medium-sized enterprises (Wang Chunhai)
- 2024 DigiKey Innovation Contest
- MCU C language programming and Proteus simulation technology (Xu Aijun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Why are there only step-up and step-down circuits but no step-down and step-down circuits?
- How to read the TMS320C6713 datasheet
- EEWORLD University ---- Live playback: ST highly flexible, easy-to-use and customizable protocol stack - Introduction to BlueBRG-LP protocol stack
- 1206 package chip capacitor working voltage 2000V
- 【GD32L233C-START Review】6. Hardware I2C drive 0.96-inch OLED
- Output waveform distortion problem of improved differential circuit
- New MicroPython Pi calculation performance comparison
- Please, administrator, please restore the ability to invite 8 people. I will no longer suggest pressing the Enter key to automatically query.
- Develop the Internet of Things in 10 minutes: Remote formaldehyde monitoring (4G module)
- MSP430 Clock Basics