/**********************************************************************/ /* This program is developed by Microsoft C 5.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 "P1202.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 P1202MC?.LIB gotoxy(1,1); // 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 +/- 5V range wRetVal+=P1202_DelayUs(3); // delay 3 us settling time wRetVal+=P1202_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=P1202_SetChannelConfig(1,0); // CH:1, ConfigCode:0 -> +/- 5V range wRetVal+=P1202_DelayUs(3); // delay 3 us settling time wRetVal+=P1202_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=P1202_SetChannelConfig(0,8); // CH:0, ConfigCode:8 -> 0-10V range wRetVal+=P1202_DelayUs(3); // delay 3 us settling time wRetVal+=P1202_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=P1202_SetChannelConfig(2,3); // CH:2, ConfigCode:3 -> +/- 0.625V range wRetVal+=P1202_DelayUs(3); // delay 3 us settling time wRetVal+=P1202_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++) P1202_DelayUs(1000); // delay 500 ms just for display purpose if( kbhit() ) break; } P1202_DriverClose(); return 0; }