/**********************************************************************/ /* This program is developed by Borland C++ 3.1 */ /***********************************************************************/ /* Demo 19: A/D Calibration: */ /* step 1: apply 0V to channel 0. */ /* step 2: apply 4.996V to channel 1. */ /* step 3: apply 0.6245V to channel 2. */ /* step 4: adjust VR101 until CAL:0 = 7ffH or 800H. */ /* step 5: adjust VR100 until CAL:1 = ffeH or fffH. */ /* step 6: repeat step 4 and step 5 until all OK. */ /* step 7: adjust VR2 until CAL:3 = 000H or 001H. */ /* step 8: adjust VR1 until CAL:4 = ffeH or fffH. */ /***********************************************************************/ #define MYLIB #include "P180X.H" int main() { int i,j; DWORD dwCount=0; WORD wBoards,wRetVal; WORD wDIOdata,wData; float fVal; WORD wAddrTimer,wAddrCtrl,wAddrDio,wAddrAdda; clrscr(); /* a clear screen function in P180XMC?.LIB */ gotoxy(1,1); /* 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 +/- 5V range */ wRetVal+=P180X_DelayUs(3); /* delay 3 us settling time */ wRetVal+=P180X_AdPolling(&fVal); if (wRetVal==0) { wData=(WORD)(fVal/5.0*2048.0)+2048; gotoxy(5,12); printf("CAL:0=%04xH\n",wData); } else { putch(0x07); putch(0x07); putch(0x07); printf("(5.0V Range) AdPolling CH:0 Error !!!\n"); exit(0); } /*-----------------------------------------------------*/ wRetVal=P180X_SetChannelConfig(1,0); /* CH:1, ConfigCode:0 -> +/- 5V range */ wRetVal+=P180X_DelayUs(3); /* delay 3 us settling time */ wRetVal+=P180X_AdPolling(&fVal); if (wRetVal==0) { wData=(WORD)(fVal/5.0*2048.0)+2048; gotoxy(5,13); printf("CAL:1=%04xH\n",wData); } else { putch(0x07); putch(0x07); putch(0x07); printf("(5.0V Range) AdPolling CH:0 Error !!!\n"); exit(0); } /*-----------------------------------------------------*/ wRetVal=P180X_SetChannelConfig(0,8); /* CH:0, ConfigCode:8 -> 0-10V range */ wRetVal+=P180X_DelayUs(3); /* delay 3 us settling time */ wRetVal+=P180X_AdPolling(&fVal); if (wRetVal==0) { wData=(WORD)(fVal/10.0*2048.0); gotoxy(5,14); printf("CAL:2=%04xH\n",wData); } else { putch(0x07); putch(0x07); putch(0x07); printf("(5.0V Range) AdPolling CH:0 Error !!!\n"); exit(0); } /*-----------------------------------------------------*/ wRetVal=P180X_SetChannelConfig(2,3); /* CH:2, ConfigCode:3 -> +/- 0.625V range */ wRetVal+=P180X_DelayUs(3); /* delay 3 us settling time */ wRetVal+=P180X_AdPolling(&fVal); if (wRetVal==0) { wData=(WORD)(fVal/0.625*2048.0)+2048; gotoxy(5,15); printf("CAL:3=%04xH\n",wData); } else { putch(0x07); putch(0x07); putch(0x07); printf("(5.0V Range) AdPolling CH:0 Error !!!\n"); exit(0); } for(i=0; i<500; i++) P180X_DelayUs(1000); /* delay 500 ms just for display purpose */ if( kbhit() ) break; } P180X_DriverClose(); return 0; }