/*****************************************************************************/ /* This program is developed by Turbo C 2.0 */ /******************************************************************************/ /* *First Card: reading all A/D channels. */ /* *For PCI-1202L user, the setting time is 3us. */ /* *For PCI-1202H user, the setting time varying according to */ /* configuration code, please refer Page 28 of NAPPCI/win user mamual. */ /* *for example: a PCI-1202H user who want to acquire A/D channel */ /* 5 with configuration code 0x11, then the following statements */ /* must be used. */ /* -> P1202_SetChannelConfig(5,0x11); // +/- 5V range */ /* -> P1202_DelayUs(28); // delay 28 us settling time */ /* -> P1202_AdPolling(&AdVal); // get the AD value into AdVal */ /******************************************************************************/ #define MYLIB #include "P1202.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 P1202 card and detect how many P1202 card in PC */ wRetVal=P1202_DriverInit(&wBoards); printf("Threr are %d P1202 Cards in this PC\n",wBoards); if( wBoards==0 ) { putch(0x07); putch(0x07); putch(0x07); printf("There are no P1202 card in this PC !!!\n"); exit(0); } /* dump every P1202 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-1202H(High Gain) -> CH:0 Config:10-1B (hex)\n"); printf("Enter Ch(dec):"); scanf("%d",&wChannel); printf("Enter Config(hex):"); scanf("%x",&wConfig); /* The P1202_ActiveBoard() function must be used to active a board, */ /* then all operation will take effect to the actived board. */ P1202_ActiveBoard( 0 ); P1202_Do(0x55aa); /* Digital output */ P1202_Di(&wDIOdata); /* Digital input */ printf("Digital Output -> 55aaH | Digital Input -> %04xH\n",wDIOdata); clrscr(); wCount=0; gotoxy(1,1); printf("First P1202 Card:"); for( ; ; ) { gotoxy(20,1); printf("Count=%d",wCount++); { wRetVal=P1202_SetChannelConfig(wChannel,wConfig); /* +/- 5V range for PCI-1202H */ 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+=P1202_DelayUs(3); */ /* 3 us settling time for PCI-1202L */ wRetVal+=P1202_DelayUs(23); /* 23 us settling time for PCI-1202H */ if( wRetVal>0 ) { printf("*** (+/- 5.0V Range) DelayUs Error ***"); printf("AD channel %02d -> Delay Error %d !!!",wChannel,wRetVal); putch(0x07); getch(); return 0; } wRetVal=P1202_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); } P1202_DriverClose(); return 0; }