/**********************************************************************/ /* This program is developed by Borland C++ 3.1 */ /***********************************************************************/ /* Demo 4: Two 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() { int i,j; WORD wBoards; WORD wRetVal,wCount,wADData; WORD wDIOdata; 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<=1 ) { putch(0x07); putch(0x07); putch(0x07); printf("Please install two P180X cards 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 55aaH | Digital Input -> %04xH\n",wDIOdata); printf("----------------------------------------------------------\n"); printf("The Second P180X Card...\n"); P180X_ActiveBoard( 1 ); P180X_Do(0xaa55); /* Digital output */ P180X_Di(&wDIOdata); /* Digital input */ printf("Digital Output -> aa55H | Digital Input -> %04xH\n",wDIOdata); printf("\nHit any key to continue...\n"); putch(0x07); getch(); /**************************************************************************/ /* For PCI-1800L/1802L user, the settling time is 3us. */ /* For PCI-1800H/1802H user, the settling 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(&fVal); // Acquire A/D data */ /**************************************************************************/ clrscr(); wCount=0; gotoxy(1,1); printf("First P180X Card:"); gotoxy(41,1); printf("Second P180X Card:"); for( ; ; ) { /*--------- To Active First P180X Card -------------------*/ gotoxy(20,1); printf("Count=%d",wCount); P180X_ActiveBoard( 0 ); for(i=0; i<16; i++) { // wRetVal=P180X_SetChannelConfig(i,0x00); // +/- 5V range for PCI-180XL wRetVal=P180X_SetChannelConfig(i,0x10); // +/- 5V range for PCI-180XH if( wRetVal>0 ) { printf("*** (+/- 5.0V Range) SetChannelConfig Error ***"); printf("AD channel %02d -> SetCh Error %d !!!",i,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 !!!",i,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 !!!",i,wRetVal); putch(0x07); getch(); return 0; } else { gotoxy(2,2+i); printf(" (+/- 5.0V) ch:%02d -> %+5.3fV | %04xH",i,fVal,wADData); } } /*--------- To Active Second P180X Card ---------------------------*/ gotoxy(60,1); printf("Count=%d",wCount); P180X_ActiveBoard( 1 ); for(i=0; i<16; i++) { // wRetVal=P180X_SetChannelConfig(i,0x00); // +/- 5V range for PCI-180XL wRetVal=P180X_SetChannelConfig(i,0x10); // +/- 5V range for PCI-180XH if( wRetVal>0 ) { printf("*** (+/- 5.0V Range) SetChannelConfig Error ***"); printf("AD channel %02d -> SetCh Error %d !!!",i,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 !!!",i,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 !!!",i,wRetVal); putch(0x07); getch(); return 0; } else { gotoxy(42,2+i); printf(" (+/- 5.0V) ch:%02d -> %+5.3fV | %04xH",i,fVal,wADData); } } wCount++; if( kbhit() ) break; for(j=0; j<100; j++) P180X_DelayUs(1000); // delay 100 ms just for display purpose } P180X_DriverClose(); return 0; }