发表于:2003-12-23 13:45:00
楼主
本人刚学习编程,用VC在2000下做的研华PCL818L的数据采集:
有时采的数差不多,有时又很莫名其妙,跟测试程序差得很多。
但是又分析不出程序中出了什么问题。请教高人指点一二!
Sleep(500);
float sam=0;
int i=0;
sam_current=0;
sam_volt=0;
/*为selPort端口选择*/
for(i=0; i<allnum;i++) {sam_current+=ReadPort(selPort-1); sam_volt+=2*ReadPort(selPort+7);}
/* 取平均值做为最终采样值*/
if(allnum>0) {sam_current=sam_current/allnum; sam_volt=sam_volt/allnum;}
ReadPort(int nPort)
{
BASE=0x300;
int inNum;
unsigned int low;
unsigned int high;
float inData;
Outport(BASE+2,nPort);
Outport(BASE+0,0);
do
inNum=(Inport(BASE+8)&0x80);
while(inNum==0x80);
low=Inport(BASE+0);
low=(low>>4)&0x0f;
high=Inport(BASE+1);
high=(high<<4)&0xff0;
inNum=low+high;
inData=-10+20*(float)inNum/4096;
if(inData<0) inData=-inData;
}