/***********************************************************************/ /* This program is developed by Turbo C 2.0 */ /***********************************************************************/ /* Demo 19: A/D Calibration: */ /* step 1: apply 0V to channel 0. */ /* step 2: apply 4.9998V to channel 1. */ /* step 3: apply +0.6245V to channel 2. */ /* step 4: adjust VR3 until CAL:0 = 0000H or FFFFH. */ /* step 5: adjust VR2 until CAL:1 = 7FFFH or 7FFEH. */ /* step 6: repeat step 4 and step 5 until all OK. */ /* step 7: adjust VR1 until CAL:3 = 0FFCH or 0FFDH. */ /***********************************************************************/ #define MYLIB #include "P1602.H" int main() { int i,j,count,wAd,wVal; DWORD dwCount=0,dwAvg; WORD wBoards,wRetVal; WORD wDIOdata,wData; float fVal,fAdVals[550],fTemp,fAvg; WORD wAddrTimer,wAddrCtrl,wAddrDio,wAddrAdda; clrscr(); gotoxy(1,1); /* 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 +/- 5V range */ wRetVal+=P1602_DelayUs(3); /* delay 3 us settling time */ fTemp=0.0; P1602_AdsPolling(fAdVals,512); for(count=0;count<512;count++) fTemp=fTemp+fAdVals[count]; fVal=fTemp/512; wData=(WORD)( fVal / 5.0 * 32768.0 ); if (wRetVal==0) { gotoxy(5,12); printf("CAL:0=%04xH | %+5.4fV\n",wData,fVal); } else { putch(0x07); putch(0x07); putch(0x07); printf("(5.0V Range) AdPolling CH:0 Error !!!\n"); exit(0); } /*-----------------------------------------------------*/ wRetVal=P1602_SetChannelConfig(1,1); /* CH:1, ConfigCode:1 -> +/- 5V range */ wRetVal+=P1602_DelayUs(3); /* delay 3 us settling time */ fTemp=0.0; P1602_AdsPolling(fAdVals,512); for(count=0;count<512;count++) fTemp=fTemp+fAdVals[count]; fVal=fTemp/512; wData=(WORD)( fVal / 5.0 * 32768.0 ); if (wRetVal==0) { gotoxy(5,13); printf("CAL:1=%04xH | %+5.4fV\n",wData,fVal); } else { putch(0x07); putch(0x07); putch(0x07); printf("(5.0V Range) AdPolling CH:0 Error !!!\n"); exit(0); } /*-----------------------------------------------------*/ wRetVal=P1602_SetChannelConfig(2,3); /* CH:2, ConfigCode:3 -> +/- 5V range */ wRetVal+= P1602_DelayUs(3); /* delay 3 us settling time */ fTemp=0.0; P1602_AdsPolling(fAdVals,512); for(count=0;count<512;count++) { fTemp=fTemp+fAdVals[count]; } fVal=fTemp/512; wData=(WORD)( fVal / 5.0 * 32768.0 ); if(wRetVal==0) { gotoxy(5,14); printf("CAL:2=%04xH | %+5.4fV\n ",wData,fVal); } else { putch(0x07); putch(0x07); putch(0x07); printf("(5.0V Range) AdPolling CH:0 Error !!!\n"); exit(0); } for(i=0; i<500; i++) P1602_DelayUs(1000); /* delay 500 ms just for display purpose */ if( kbhit() ) break; } P1602_DriverClose(); return 0; }