在单片机控制系统中,经常会涉及到上位机与下位机的通信。本文主要通过一个简单的实例来介绍labVIEW与单片机的串口通信实现过程,包括下位机单片机的硬件与软件设计,上位机LabVIEW的前面板和程序框图设计。
1.概述
在现代测控系统中,我们经常会采用上位机和下位机的开发控制模式。下位机主要是用来采集数据,可以通过嵌入式控制器、单片机控制器、PLC等来实现。上位机主要是图形界面,用来实时显示采集数据,并进行数据分析及处理,同时可以控制下位机。上位机的实现可以通过各种高级语言,比如VB、Delphi等以及NI公司的图形化虚拟仪器软件开发环境LabVIEW.由于LabVIEW采用的是图形化的编程方法,所以无论你是否有过编程经验,都可以快速、高效地设计用户界面,实现与控制硬件的通信,并进行数据分析和处理。如今LabVIEW已经渗透到工业测量的各个领域,与此同时在嵌入式、FPGA、DSP、实时控制等领域也发挥着巨大的作用。
2.本实例实现的功能
首先利用单片机STC89C54通过串口发送“你好,LabVIEW”,LabVIEW将单片机发送到数据进行显示。通过这个实例来了解LabVIEW的串口通信设计。
3.下位机硬件设计与软件设计
(1)硬件设计
单片机串口通信硬件电路设计比较简单,主要包括单片机STC89C54最小系统以及MAX232和九针串口。
(2)软件设计
设计源码如下:
#include
#define uchar unsigned char
#define uint unsigned int
void SendStr(unsigned char *s);//发送
字符串
void DelayMs(uint xms)//延时子函数
{
uint i,j;
for(i=xms;i>0;i-)
for(j=110;j>0;j-);
}
void InitUART(void) //串口初始化
{
SCON=0×50; //SCON:模式
1,8-bitUART,使能接收
TMOD|=0×20; //TMOD:timer 1,mode
2,8-bit重装
TH1=0xFD; // TH1:重装值9600波
特率 晶振11.0592MHz
TR1=1; //TR1:timer 1打开
EA=1; //打开总中断
}
void main(void)
{
InitUART();
while(1)
{
SendStr(“你好!LabVIEW!”);
DelayMs(240);
DelayMs(240);
}
}
void SendByte(unsigned char dat)
{
SBUF=dat;
while(!TI);
TI=0;
}
void SendStr(unsigned char *s)
{
while(*s!='
相关文章









