/*****************************************************************************/ /* 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 15, then display */ /* the scanned A/D value. */ /******************************************************************************/ #define MYLIB #include "P1602.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 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 CH:0 Config:0-B (hex)\n"); printf("Enter Ch(dec):"); scanf("%d",&wChannel); printf("Enter Config(hex):"); scanf("%x",&wConfig); /* The P1602_ActiveBoard() function must be used to active a board, */ /* then all operation will take effect to the actived board. */ P1602_ActiveBoard( 0 ); P1602_Do(0x55aa); /* Digital output */ P1602_Di(&wDIOdata); /* Digital input */ printf("Digital Output -> 55aaH | Digital Input -> %04xH\n",wDIOdata); clrscr(); wCount=0; gotoxy(1,1); printf("First P1602 Card:"); for( ; ; ) { gotoxy(20,1); printf("Count=%d",wCount++); { wRetVal=P1602_SetChannelConfig(wChannel,wConfig); // +/- 5V range for PCI-1602 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+=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 !!!",wChannel,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 !!!",wChannel,wRetVal); putch(0x07); getch(); return 0; } else { gotoxy(2,2+i); printf(" (+/- 5.0V) ch:%02d -> %+5.4fV", wChannel,fVal); } } if( kbhit() ) break; delay(500); } P1602_DriverClose(); return 0; }