Implementation of Serial Communication between LabVIEW and STC89C54 MCU

Publisher:PeacefulAuraLatest update time:2014-02-14 Source: dzscKeywords:LabVIEW Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  1. Overview

  In modern measurement and control systems, we often use the development and control mode of the host computer and the slave computer. The slave computer is mainly used to collect data, which can be realized through embedded controllers, single-chip microcomputer controllers, PLCs, etc. The host computer is mainly a graphical interface, which is used to display the collected data in real time, analyze and process the data, and control the slave computer at the same time. The host computer can be realized through various high-level languages, such as VB, Delphi, etc., as well as NI's graphical virtual instrument software development environment LabVIEW. Since LabVIEW uses a graphical programming method, whether you have programming experience or not, you can quickly and efficiently design the user interface, realize communication with the control hardware, and perform data analysis and processing. Today, LabVIEW has penetrated into various fields of industrial measurement, and at the same time it also plays a huge role in embedded, FPGA, DSP, real-time control and other fields.

  2. Functions implemented in this example

  First, use the microcontroller STC89C54 to send "Hello, LabVIEW" through the serial port, and LabVIEW will send the microcontroller to the data for display. Through this example, you can understand the serial communication design of LabVIEW.

  3. Hardware design and software design of the lower computer

  (1) Hardware design

  The hardware circuit design of the microcontroller serial port communication is relatively simple, mainly including the microcontroller STC89C54 minimum system, MAX232 and a nine-pin serial port.

  (2) Software Design

  The design source code is as follows:

  #include

  #define uchar unsigned char

  #define uint unsigned int

  void SendStr(unsigned char *s); //send

  String

  void DelayMs (uint xms) //delay sub-function

  {

  uint i,j;

  for(i=xms;i>0;i-)

  for(j=110;j>0;j-);

  }

  void InitUART(void) //Serial port initialization

  {

  SCON=0×50; //SCON: mode

  1,8-bitUART,receive enabled

  TMOD|=0×20; //TMOD:timer 1,mode

  2,8-bit reinstall

  TH1=0xFD; // TH1: reload value 9600 waves

  Crystal Oscillator: 11.0592MHz

  TR1=1; //TR1: timer 1 is turned on

  EA=1; //Open the general interrupt

  }

  void main(void)

  {

  initUART();

  while(1)

  {

  SendStr("Hello! LabVIEW!");

  DelayMs(240);

  DelayMs(240);

  }

  }

  void SendByte(unsigned char dat)

  {

  SBUF=dat;

  while(!TI);

  TI=0;

  }

  void SendStr(unsigned char *s)

  {

  while(*s!=\'\\0')//\\0 indicates the end of the string

  Flag, // detect whether the string ends

  {

  SendByte(*s);

  s++;

  }[page]

  4. Host computer LabVIEW front panel and program flowchart

  (1) Introduction to related functions

  When doing LabVIEW serial communication, you must first install the VISA driver, which can be downloaded from the Internet. LabVIEW's operations on the serial port are mainly read and write operations. This example mainly receives data, that is, read operations. Here we first introduce the controls and functions related to this example.

  ①VISA resource name

  Under the "New" control tab, under the "I/O" sub-tab, there is a "VISA Resource Name" control. After installing the VISA driver and connecting to the hardware, the corresponding COM ports can be listed under this control, and you can select the appropriate COM port.

  ②VISA configures the serial port function

  This function is located in the "Instrument I/O"

  The sub-tabs are mainly used to configure the serial port parameters, including baud rate, data bits, parity check, etc.

  ③VISA read and VISA close functions

  The VISA Read function reads a specified number of bytes from the device or interface specified by the VISA resource name and returns the data to the read buffer. The VISA Close function closes the device session handle or event object specified by the VISA resource name.

  (2) Program flowchart design

  The program flowchart design is shown in Figure 1.

  

  5. Testing

  After connecting the hardware, power on, download the program, and run labVIEW, we can see that the string "Hello! LavVIEW" sent by the microcontroller is received in the read buffer, as shown in Figure 2.

  

  6. Summary

  The host computer is designed using LabVIEW, which has a beautiful interface and is easy to implement. It can be easily used in various measurement and monitoring systems.

Keywords:LabVIEW Reference address:Implementation of Serial Communication between LabVIEW and STC89C54 MCU

Previous article:Design and production of a simple digital voltmeter
Next article:Research on single chip intelligent lighting dimming system

Latest Microcontroller Articles
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号