/* ------------------------------------------------------------ */ /* DEMO1.C : PISO-813 */ /* Note : Measure 32-channel A/I.Bipolar range: -10V - +10V */ /* ------------------------------------------------------------ */ #include "MSCPIO.H" WORD Read_AD_Data(void); WORD wBase,wIrq; int main() { int i,l,h,x,y; WORD wBoards,wRetVal,AdResult,t1,t2,t3,t4,t5; WORD wSubVendor,wSubDevice,wSubAux,wSlotBus,wSlotDevice; char c; float ok,err,v,k; clrscr(); /* step 1: find address-mapping of PIO/PISO cards */ wRetVal=PIO_DriverInit(&wBoards,0x80,0x0a,0x00); /* for PISO-813 */ printf("\nThrer are %d PISO-813 Cards in this PC",wBoards); if (wBoards==0) exit(0); printf("\n--------------- The Configuration Space ---------------"); for(i=0; i "); ShowPioPiso(wSubVendor,wSubDevice,wSubAux); } PIO_GetConfigAddressSpace(0,&wBase,&wIrq,&t1,&t2,&t3,&t4,&t5); /* step 2: enable all D/I/O port */ outp(wBase+0,1); /* enable D/I/O */ i=0;x=1;y=1; clrscr(); /* Delay more than 5.6us for PGA gain change and optocouple */ /* propagation delay 6.0us. (5.6+6.0)us */ outp(wBase+0xe4,0x00); /* Gain control,G=1 */ delay1(1000); for(;;) { gotoxy(x,y); printf("Channel %2d ",i); outp(wBase+0xe0,i); /* channel select = i*/ delay1(200); outp(wBase+0xf0,0x00); /* software trigger */ delay1(200); AdResult=Read_AD_Data(); k=((float)AdResult-2047.0)*10.0/2048.0; printf(",value = %2.4f",k); i++; if (i==0x20) i=0; y=i+1; x=1; if (i>=16) { x=40; y=i-15; } if (kbhit()!=0) { c=getch(); if ((c=='q') || (c=='Q')) break; } } gotoxy(1,20); PIO_DriverClose(); } /* -------------------------------------------------------------- */ WORD Read_AD_Data(void) { int LowByte; WORD HighByte,Data; char c; do { HighByte=inp(wBase+0xd4); /* Read high byte of A/D data */ if (kbhit()!=0) break; } while(HighByte&0x10);/* Chech status until convertion complete */ LowByte=inp(wBase+0xd0); Data=((HighByte<<8)+LowByte)&0xfff; return(Data); }