/******************************************************************************/ /* This program is developed by Borland C++ 3.1 */ /******************************************************************************/ /* *First Card: reading all A/D channels. */ /* *For PCI-1602/1602F user, the setting time is 3us. */ /* *For PCI-1602/1602F user, the setting time varying according to */ /* configuration code, please refer Page 28 of NAPPCI/win user mamual. */ /* *for example: a PCI-1602/1602F user who want to acquire A/D channel */ /* 5 with configuration code 1, then the following statements */ /* must be used. */ /* -> P1602_SetChannelConfig(5,1); // +/- 5V range */ /* -> P1602_DelayUs(3); // delay 3 us settling time */ /* -> P1602_AdPolling(&AdVal); // get the AD value into AdVal */ /******************************************************************************/ /* Demo 3: One P1602 Card demo. */ /* To repeat sacn the A/D from CH:0 to CH 31, then display */ /* the scanned A/D value. */ /******************************************************************************/ #include "P1602.H" int main() { WORD i,j; WORD wBoards; WORD wRetVal,wCount,wADData,wData; WORD wDIOdata; DWORD dwExact,dwOKs,dwErrors,dwScanCount,dwP1,dwP2,dwStatus; float fVal,fAdVals[5]; WORD wAddrTimer,wAddrCtrl,wAddrDio,wAddrAdda; /* initiaing P1602 card and detect how many P1602 card in PC */ wRetVal=P1602_DriverInit(&wBoards); printf("Threr are %d P1602 Cards in this PC\n",wBoards); if( wBoards==0 ) { putch(0x07); putch(0x07); putch(0x07); printf("There are no P1602 card in this PC !!!\n"); exit(0); } /* dump every P1602 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("Hit any key to continue...\n"); putch(0x07); getch(); clrscr(); wCount=0; gotoxy(1,1); printf("First P1602 Card:"); for( ; ; ) { gotoxy(20,1); printf("Count=%d",wCount++); for(i=0; i<16; i++) { wRetVal=P1602_SetChannelConfig(i,1); /* +/- 5V range for PCI-1602 */ if( wRetVal>0 ) { printf("*** (+/- 5.0V Range) SetChannelConfig Error ***"); printf("AD channel %02d -> SetCh Error %d !!!",i,wRetVal); putch(0x07); getch(); return 0; } wRetVal+=P1602_DelayUs(3); /* 3 us settling time for PCI-1602 */ if( wRetVal>0 ) { printf("*** (+/- 5.0V Range) DelayUs Error ***"); printf("AD channel %02d -> Delay Error %d !!!",i,wRetVal); putch(0x07); getch(); return 0; } wRetVal=P1602_AdPolling(&fVal); wADData=(WORD)( fVal / 5.0 * 32768.0 ); 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.4fV | %04xH ",i,fVal,wADData); } /*-----------------------------------------------------------*/ wRetVal=P1602_SetChannelConfig(i+16,1); /* +/- 5V range for PCI-1602 */ if( wRetVal>0 ) { printf("*** (+/- 5.0V Range) SetChannelConfig Error ***"); printf("AD channel %02d -> SetCh Error %d !!!",i+16,wRetVal); putch(0x07); getch(); return 0; } wRetVal+=P1602_DelayUs( 3); /* 3 us settling time for PCI-1602 */ if( wRetVal>0 ) { printf("*** (+/- 5.0V Range) DelayUs Error ***"); printf("AD channel %02d -> Delay Error %d !!!",i+16,wRetVal); putch(0x07); getch(); return 0; } wRetVal=P1602_AdPolling(&fVal); wADData=(WORD)( fVal / 5.0 * 32768.0); if( wRetVal>0 ) { printf("*** (+/- 5.0V Range) AdPolling Error ***"); printf("AD channel %02d -> Polling Error %d !!!",i+16,wRetVal); putch(0x07); getch(); return 0; } else { gotoxy(40,2+i); printf(" ch:%02d -> %+5.4fV | %04xH",i+16,fVal,wADData); } } if( kbhit() ) break; delay(500); } P1602_DriverClose(); return 0; }