利用Labwindows/CVI编制与PIC单片机通讯程序 点击:559 | 回复:0



xilinxue

    
  • 精华:13帖
  • 求助:0帖
  • 帖子:367帖 | 3回
  • 年度积分:0
  • 历史总积分:0
  • 注册:1900年1月01日
发表于:2010-02-28 21:59:14
楼主
查看文章

利用Labwindows/CVI编制与PIC单片机通讯程序
2009-11-01 12:27
利用Labwindows/CVI编制与PIC单片机通讯程序

NI 公司的图形化编程软件LabView已经成为业界常用的测试软件。很多软件测试工程师都在使用其编制测试软件。但对于C语言更加熟悉的工程师而言,LabWindows/CVI更加适合。

使用LabWindows/CVI中的串口通信函数,可以很方便的通过PC机的232串口,并通过PIC的UART口,与PIC单片机进行通信。

程序如下

#i nclude "read.h"
#i nclude "toolbox.h"
#i nclude <cvirte.h>
#i nclude <userint.h>
#i nclude "com.h"
#i nclude <rs232.h>
#i nclude <ansi_c.h>
#i nclude <formatio.h>

static int panelRead;

# include <stdio.h>
# include <stdlib.h>

int i="0";
ch ar * itoa(int val, ch ar* string, int radix) ;
static int panelHandle;
/*define the global variable*/
int comselect,strLen,data【55】,btlselect,jhselect,longselect,stopselect;
int status,k,m,*s,capvalue;
unsigned ch ar info【20】,readBusf【20】;

int main (int argc, ch ar *argv【】)
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelRead = LoadPanel (0, "read.uir", PANEL_Read)) < 0)
return -1;
DisplayPanel (panelRead);
RunUserInterface ();
DiscardPanel (panelRead);
return 0;
}


//int main (int argc, ch ar *argv【】)
//{
// if (InitCVIRTE (0, argv, 0) == 0) /* Needed if linking in external compiler;harmless otherwise*/
// return -1; /* out of memory */
// if ((panelHandle = LoadPanel (0, "com.uir", PANEL)) < 0)
// return -1;
// DisplayPanel (panelHandle);
// RunUserInterface ();
// DiscardPanel (panelHandle);
// return 0;
//}


//Send Text Routine
/*int CVICALLBACK Send (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
FlushInQ(comselect);
FlushOutQ(comselect);
//get the send text
GetCtrlVal(panelHandle,PANEL_SENDTEXT,info);
//Send
status=ComWrt(comselect,info,strlen(info));
if(status!=strlen(info))
MessagePopup("Error","Send data failed!");

break;
}
return 0;
} */

/*int CVICALLBACK ClearSend (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
ResetTextBox(panelHandle,PANEL_SENDTEXT,"\0");

break;
}
return 0;
} */


//Receive Text
int CVICALLBACK Receive (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{

int i="0",k=0; ch ar string【20】,change【20】; double capvalue="0" ;
double value;
switch (event)
{
case EVENT_COMMIT:
info【0】=‘/‘;
info【1】=‘R‘;
info【2】=0x10;
info【3】=‘?‘;
status=ComWrt(comselect,info,strlen(info));
if(status!=strlen(info))
MessagePopup("Error","Send data failed!");
//receive
do{
status=ComRd(comselect,readBusf,strlen(info));
if(status!=strlen(info))
{
MessagePopup("Error","read data failed!");
break;
}
}while(readBusf【0】!=‘o‘) ;

do
{
i="i"+1;
status="ComRd"(comselect,readBusf,strlen(info));

k="readBusf"【0】;

sprintf(readBusf,"%02X",k); //数字转字符串 d:deci x: hex
SetTableCellVal(panelHandle


热门招聘
相关主题

官方公众号

智造工程师