/*****************************************************************************/ /* This program is developed by Turbo C 2.0 */ /******************************************************************************/ /* *First Card: reading all A/D channels. */ /* *For PCI-1800L/1802L user, the setting time is 3us. */ /* *For PCI-1800H/1802H user, the setting time varying according to */ /* configuration code, please refer Page 28 of NAPPCI/win user mamual. */ /* *for example: a PCI-1800H/1802H user who want to acquire A/D channel */ /* 5 with configuration code 0x11, then the following statements */ /* must be used. */ /* -> P180X_SetChannelConfig(5,0x11); // +/- 5V range */ /* -> P180X_DelayUs(28); // delay 28 us settling time */ /* -> P180X_AdPolling(&AdVal); // get the AD value into AdVal */ /******************************************************************************/ /* Demo 3: One P180X Card demo. */ /* To repeat sacn the A/D from CH:0 to CH 15, then display */ /* the scanned A/D value. */ /******************************************************************************/ #define MYLIB #include "P180X.H" int main() { WORD i,j; WORD wBoards; WORD wRetVal,wCount,wADData; WORD wDIOdata,wChannel,wConfig; DWORD dwExact,dwOKs,dwErrors,dwScanCount,dwP1,dwP2,dwStatus; float fVal,fAdVals[5]; WORD wAddrTimer,wAddrCtrl,wAddrDio,wAddrAdda; /* initiaing P180X card and detect how many P180X card in PC */ wRetVal=P180X_DriverInit(&wBoards); printf("Threr are %d P180X Cards in this PC\n",wBoards); if( wBoards==0 ) { putch(0x07); putch(0x07); putch(0x07); printf("There are no P180X card in this PC !!!\n"); exit(0); } /* dump every P180X card's configuration address space */ printf("The Configuration Space -> Timer Control DIO AD/DA\n"); for(i=0; i CH:0 Config:0-B (hex)\n"); printf(" PCI-180XH(High Gain) -> CH:0 Config:10-1B (hex)\n"); printf("Enter Ch(dec):"); scanf("%d",&wChannel); printf("Enter Config(hex):"); scanf("%x",&wConfig); /* The P180X_ActiveBoard() function must be used to active a board, */ /* then all operation will take effect to the actived board. */ P180X_ActiveBoard( 0 ); P180X_Do(0x55aa); /* Digital output */ P180X_Di(&wDIOdata); /* Digital input */ printf("Digital Output -> 55aaH | Digital Input -> %04xH\n",wDIOdata); clrscr(); wCount=0; gotoxy(1,1); printf("First P180X Card:"); for( ; ; ) { gotoxy(20,1); printf("Count=%d",wCount++); { wRetVal=P180X_SetChannelConfig(wChannel,wConfig); /* +/- 5V range for PCI-180XH */ if( wRetVal>0 ) { printf("*** (+/- 5.0V Range) SetChannelConfig Error ***\n"); printf("AD channel %02d -> SetCh Error %d !!!\n",wChannel,wRetVal); putch(0x07); getch(); return 0; } /* wRetVal+=P180X_DelayUs(3); */ /* 3 us settling time for PCI-180XL */ wRetVal+=P180X_DelayUs(23); /* 23 us settling time for PCI-180XH */ if( wRetVal>0 ) { printf("*** (+/- 5.0V Range) DelayUs Error ***"); printf("AD channel %02d -> Delay Error %d !!!",wChannel,wRetVal); putch(0x07); getch(); return 0; } wRetVal=P180X_AdPolling(&fVal); wADData=(WORD)(fVal/5.0*2048.0+2048); if( wRetVal>0 ) { printf("*** (+/- 5.0V Range) AdPolling Error ***"); printf("AD channel %02d -> Polling Error %d !!!",wChannel,wRetVal); putch(0x07); getch(); return 0; } else { gotoxy(2,2+i); printf(" (+/- 5.0V) ch:%02d -> %+5.3fV", wChannel,fVal); } } if( kbhit() ) break; delay(500); } P180X_DriverClose(); return 0; }