Using PC to realize single chip microcomputer optimization control

Publisher:bln898Latest update time:2012-01-30 Source: 浙江工贸职业技术学院学报 Keywords:PC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. The necessity of using PC to realize single chip microcomputer optimization control

At present, the control of single-chip microcomputer is very extensive. However, for complex field control, most of the control programs of single-chip microcomputer are written in a single assembly language.

Its disadvantages are:

1. Due to the limitation of assembly language function, it is impossible to form a friendly control interface and cannot well reflect the real-time changes of the control site.

2. Different single-chip CPU chips require different assembly languages, which have poor portability and increase the difficulty of programming.

3. When the process conditions of the controlled object change, it is difficult for the microcontroller to follow the changes. Unless the program is reprogrammed and solidified again, it will be difficult to operate.

The author adopts the combination of PC high-level language programming and MCU assembly language programming to solve the above shortcomings.

2. Implementation process

The PC sends various preset signals to the single-chip control system through the serial port, and then the single-chip system generates actual analog signals through D/A conversion and sends them to the site; the preset values ​​can be displayed on the software window of the PC. At the same time, the signal measured by the sensor on site is sent to the single-chip microcomputer for analysis and processing through A/D conversion, and the error data is obtained by comparing it with the preset value. The error data is sent to the control site for precision adjustment, thus forming a closed-loop control system. At the same time, the single-chip microcomputer sends the measured accurate data to the PC through the serial port and displays it on the software window for the operator to view, record and adjust the control. The key is that if the process conditions of the control object change, you only need to change the preset data to the required data on the PC. In the following system example, the author uses a temperature control system developed by himself.

1. Microcontroller assembly language part

After designing the control circuit, the initialization part of the microcontroller control is completed using traditional assembly language. The initialization includes the serial port receiving and sending data, A/D, D/A and other functions. The rest is completed by the PC. Most readers are familiar with this part, so I will not go into details here. For details, please see the example demonstration part below. It should be noted that the program interface and implementation process of serial communication should be left in the initialization program.

(II) PC high-level language part

In the PC high-level language programming, the author uses VISUAL BASIC high-level language. VISUAL BASIC (VB) is an object-oriented high-level programming language launched by MICROSOFT. It is popular among programmers for its simple programming, rich ActiveX controls, good portability and powerful functions. Therefore, VB is used in the high-level language programming of this system.

1. Completion of the control interface

This system is explained using the temperature control system as an example.

Using high-level language programming, a very friendly and intuitive human-machine control interface can be compiled on the PC. The original direct human control is changed to indirect control by mouse and keyboard; and the control can be easily realized through the intuitive control interface, and the control situation on site is clear at a glance, which increases the operator's visual sense and sense of security and simplifies the operation.

The control interface includes: on-site data display, preset data input, upper and lower limits of on-site data, alarm prompts, data recording, time and date, data printing, password for use of this program, etc.

2. PC external communication

This part is an important part of this system. The data of the PC can be set, but sending the data of the PC to the serial port and how to receive the data from the serial port are the key parts in PC programming.

Among the numerous controls in VB, there is a MSCOmm control, which is specially used to realize the transmission and reception of serial port data, providing serial communication function for the application, and is a standard 10-bit serial port communication. This design uses this control. The following is an introduction to the use of this control.

Control properties:

commport

Set and return the communication port number. The syntax is:

object.comport[=value]

value is an integer value indicating the port number used

Note: During design, value can be set to any number from 1 to 16, and the port number must be set before opening the port.

settings

Set and return parameters such as baud rate, parity, data bits, stop bits, etc.

The syntax is: object.settings[=value]

value is a string expression that indicates the setting value of the port. It consists of four setting values ​​in the following format:

"BBBB, P, D, S"

Among them, BBBB is the baud rate; P is the parity check; D is the data bit; S is the stop bit number. It is worth noting that the setting value here must be consistent with the serial port baud rate setting value of the microcontroller system.

portooen

Set and return the status of the communication port;

The syntax is: object.portopen[=value]

value is a Boolean expression indicating the status of the communication port;

value=true: port is open; value=false: port is closed

It should be noted that if the DTREnable or RtsENable property is set to true before the port is opened, these two properties must be set to false when the port is closed.

Input

Returns and deletes the data stream in the receive buffer

The syntax is: object.input

Description: The inputlen attribute determines the number of characters read by the input attribute. If inputlen is set to 0, the input attribute reads the entire contents of the buffer. The inputmode attribute determines the type of data read by input. If inputmode=cominputmodetext, the input attribute returns text data through a variant; if inputmode=cominputmodebinary is set, the input attribute returns an array of binary data through a variant.

output

Write data stream to the transfer buffer

The syntax is: object.output[=value]

value is a string to be written to the transmit buffer.

Description: The output attribute can transmit text data or binary data

commevent

Returns the most recent communication event or error. Use this property to handle abnormal events during data transmission.

handshaking

Set and return the hardware handshake protocol

The syntax is: object.handshaking[=value]

value is an integer value

value=0 no handshake

value=1 (xon/xoff) handshake

value=2 (rts/cts) handshake

value=3 (both xon/xoff and rts/cts are acceptable) handshake

Description: Handshaking refers to the internal communication protocol through which data is transferred from the hardware port to the receive buffer. The handshake protocol ensures that data is not lost when the buffer is overloaded.

Control events:

oncomm

The oncomm event is generated whenever the value of the commevent property changes. It indicates that a communication event or an error has occurred. The commevent property contains the actual error or the code that generated the oncomm event. However, when the rthreshold or sthreshold property is set to 0, the comevreceive and comevsend events are invalid respectively.

3. Serial communication between MCU and PC

After this process, the single-chip microcomputer and the PC are connected for communication control, and the advanced programming of the PC to control the single-chip microcomputer is truly realized. In the communication, I use serial communication. The advantages of using serial communication are simplicity, strong anti-interference, and long transmission distance. The interface is RS232C interface. However, since RS232C or other serial communication interfaces cannot meet the transmission requirements of TTL level, a level conversion device must be added to this interface. The Max232 level conversion chip used here is Max's Max232.

The upper computer of the system is composed of a (PC586) microcomputer, and the high-level language is VISUAL BASIC. Through VB programming design, it is easy to make a very intuitive interface. On the interface, there is a "thermometer" to display the current temperature of the control site, and there is also a "digital" to display the temperature; the preset button on the interface can set the control temperature value of the site; for safety, the upper and lower limit temperature control devices are made on the control interface. If it exceeds the specified range, prompts and alarms will be issued, and the system will automatically adjust the furnace temperature to a safe range. If the problem cannot be solved within 1 minute, the system will automatically shut down. Moreover, if the temperature of the furnace needs to be changed, it can be achieved by presetting the computer data without changing the curing program of the single-chip microcomputer. Therefore, when the process conditions of the control object change, under the action of the PC, it is easy to meet the control conditions, thereby realizing the optimization of control.

The CPU of this system uses ATMel89C51 chip. 89C51 comes with 2K flash memory, which is very convenient to use. 89C51 is compatible with all 51 systems, has good performance and is relatively cheap. 89C51 uses its own serial port to receive the preset serial data from the PC, and then outputs it from the parallel port to the data latch 74LS373. Finally, the latched data is sent to the D/A conversion interface chip DAC0832, converted into an analog signal, and sent to the temperature control system. The temperature control system receives the analog signal from the D/A and converts it into a pulse to trigger the bidirectional thyristor. By changing the size of the conduction angle of the bidirectional thyristor, the size of the current in the heating device is changed. According to Q=I2Rt, it can be seen that changing the heat also changes the temperature. At the same time, through the role of the temperature sensor, the temperature of the site is collected from the site, and after sampling and holding, data latching, and D/A conversion, it is sent to 89C51, and compared and analyzed with the preset data to obtain error data. The error data is used to adjust the output of 89C51. After a series of transformations, the temperature on site is changed to improve the control accuracy. In addition, the single-chip microcomputer system sends the temperature data on site to the PC through the serial port and displays it on the control interface.

3.1 PC part

The VB communication control design software is as follows:

Global comm._time as integer; define global variables

Global data(1000) As Integer

Global Receive(1000) As Integer; serial data receiving and sending

Private Sub Form_load( )

Comm1.Comport=1

Comm1.Settings=”9600,N,8,1”

Comm1.Inputlen=0

Comm1.Inbuffersize=256

Comm1.Outbuffersize=256

Comm1.Portopen=true

Comm1.Sthreshold=1

Comm1.Rthreshold=1

End Sub

Public Sub send-data(); (data sending program)

For i=0 to n

Comm1.output=Chr(data(i))

Next I

End Sub

Public Sub Comm1_oncomm(); (receiving procedure)

Select Case Comm1.CommEvent

Case comEvreceive

Receive(comm._time)=Asc(Comm1.Input)

Comm_time=Comm_time+1

End Select

End Sub

(There are many more programs, but due to space limitations, the list of other programs is omitted)

3. Conclusion

After the successful development of this system, the use effect is good. If there are multiple control objects, it can form a distributed control system. Of course, due to the limited level, there are definitely many shortcomings, and readers are welcome to correct them.

References

[1] Wu Chengbin, ed. VB50 Practical Programming Guide. University of Electronic Science and Technology Press. March 1998.

[2] Li Hua, ed. Practical Interface Technology of MCS-51 Series Microcontrollers. Beijing University of Aeronautics and Astronautics Press (third printing). August 1997.
Keywords:PC Reference address:Using PC to realize single chip microcomputer optimization control

Previous article:Use highly integrated clock system chip to replace traditional separate clock design
Next article:Design of high-precision electronic balance based on MSP430F4250

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

The realization method of serial communication between single chip microcomputer and PC
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
[Microcontroller]
The realization method of serial communication between single chip microcomputer and PC
Former Huawei executive Wang Chenglu said there will be a Hongmeng PC version of the system in 2024
According to news on September 3, the HarmonyOS operating system is an operating system independently developed by Huawei. It was first unveiled at the Huawei Developer Conference on August 9, 2019. It is a full-scenario distributed OS based on microkernel and adopts a distributed architecture. , able to achieve a sea
[Embedded]
SP, LR, PC usage in ARM
MOV PC,LR Look at the following ARM assembly BL NEXT; Jump to subroutine .........; Execute NEXT at NEXT .......... MOV PC,LR; Return from subroutine BL here means jump, LR (R14) saves the return address PC (R15) is the current address, giving LR to PC means returning from the subroutine Here is a summary Fir
[Microcontroller]
Two Schemes of Serial Communication between TMS320VC5402 and PC
1 Introduction General-purpose digital signal processors (DSPs) have been widely used in high-speed digital signal processing due to their strong data processing capabilities. TMS320VC5402 (hereinafter referred to as C5402) is a fixed-point DSP chip specially designed to achieve low power consumption and high perform
[Microcontroller]
Two Schemes of Serial Communication between TMS320VC5402 and PC
Serial data exchange between PIC microcontroller and PC
1. Introduction The PIC series of microcontrollers from Microchip of the United States is a new type of CMOS process microcontroller. Many of them have internal asynchronous communication modules, such as the PIC16F877 series chips. Although the microcontroller can be equivalent to a CPU in use, in many
[Microcontroller]
Serial data exchange between PIC microcontroller and PC
Application of CAN-bus and PC in modern intelligent building community security
Preface With the continuous changes in social lifestyles and the continuous advancement of science and technology, people are demanding more humane and intelligent living conditions. Instead of doing everything by themselves, let the intelligent system replace the manual method as much as possible to
[Power Management]
Application of CAN-bus and PC in modern intelligent building community security
Toshiba's remaining PC production line assets were acquired by Sharp, officially withdrawing from the PC industry
Recently, Toshiba is announcing its exit from the ranks of the Japanese tech giants in the PC industry, with Sharp now owning the remaining assets of Toshiba's computer product line. Reports claim that Toshiba has quietly sold the remaining 19.9% ​​of its Dynabook laptop brand to Sharp, officially exiting the laptop b
[Embedded]
Toshiba's remaining PC production line assets were acquired by Sharp, officially withdrawing from the PC industry
Discussion on the Design of Serial Communication between PC and Multiple MCS-51 Single Chip Microcomputers
Introduction: This paper mainly discusses the design of serial communication between PC and multiple MCS-51 microcontrollers. The software and hardware of this system have been debugged on IBM PC/XT and DICE series MCS-51 microcontrollers and run well. Its control on the simulation platform has been verified and is no
[Microcontroller]
Discussion on the Design of Serial Communication between PC and Multiple MCS-51 Single Chip Microcomputers
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号