/***********************************************************************/ /* This program is developed by Borland C++ 3.1 */ /***********************************************************************/ /* Demo 9: one P1602 card M_FUN_3 demo. */ /* To acquire A/D CH:0, CH:1, CH:2 250 times. */ /***********************************************************************/ #define MYLIB #include "P1602.H" int iLine; WORD wAdNum=250; /* how many data is scan for a A/D channel */ float fAdBuf[750]; /* stored the acquired data. 0-249 is the data for CH:0, */ /* 250-499 is the data for CH:1, 500-750 data for CH:2 */ WORD wDaFreq=180; /* D/A output frequency is 1.8M/wDaFreq */ WORD wAdClk=80; /* A/D sampling rate is 8M/wAdClk */ WORD wDa[320],wAd[750]; WORD wPlot0[512]; /* transformed into wave form */ int main() { int i,j; WORD wBoards,wRetVal; WORD wDIOdata; char cShow[80]; DWORD dwExact,dwOKs,dwErrors,dwScanCount,dwP1,dwP2,dwStatus; WORD wChannel[32],wConfigCode[32]; WORD wDaWave=180; float fDaMagnitude=2.5,dfAdFrequency; 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 1234H | Digital Input -> %04xH\n",wDIOdata); /************** M3 Function ****************************/ for(i=0; i<750; i++) fAdBuf[i]=0.0; for(i=0; i<32; i++) wChannel[i]=0; wChannel[0]=wChannel[1]=wChannel[2]=1; for(i=0; i<32; i++) wConfigCode[i]=0; wRetVal=P1602_M_FUN_3(wDaFreq,wDaWave,fDaMagnitude,wAdClk,wAdNum, wChannel,wConfigCode,fAdBuf,-10.0,+10.0); printf("[ 0]=%+4.2f, [ 1]=%+4.2f, [ 2]=%+4.2f, [ 3]=%+4.2f\n", fAdBuf[0],fAdBuf[1],fAdBuf[2],fAdBuf[3]); printf("[250]=%+4.2f, [251]=%+4.2f, [252]=%+4.2f, [253]=%+4.2f\n", fAdBuf[250],fAdBuf[251],fAdBuf[252],fAdBuf[253]); printf("[500]=%+4.2f, [501]=%+4.2f, [502]=%+4.2f, [503]=%+4.2f\n", fAdBuf[500],fAdBuf[501],fAdBuf[502],fAdBuf[503]); putch(0x07); printf("Hit any key to continue...\n"); getch(); graphic_init(); cleardevice(); setcolor(RED); sprintf(cShow,"First P1602 Card: CH0,CH1,CH2"); outtextxy(10,10,cShow); for(i=0; i<250; i++) /* channel 0's data and its wave form */ { wPlot0[i]=50-(WORD)(fAdBuf[i]*12.0); } for(i=0; i<249; i++) /* plot channel 0's wave form */ { line(10+i,wPlot0[i],10+i+1,wPlot0[i+1]); } /*------------------------------------------------*/ for(i=0; i<250; i++) /* channel 1's data and its wave form */ { wPlot0[i]=150-(WORD)(fAdBuf[250+i]*12.0); } for(i=0; i<249; i++) /* plot channel 1's wave form */ { line(10+i,wPlot0[i],10+i+1,wPlot0[i+1]); } /*------------------------------------------------*/ for(i=0; i<250; i++) /* channel 2's data and its wave form */ { wPlot0[i]=250-(WORD)(fAdBuf[500+i]*12.0); } for(i=0; i<249; i++) /* plot channel 2's wave form */ { line(10+i,wPlot0[i],10+i+1,wPlot0[i+1]); } getch(); cleardevice(); closegraph(); P1602_DriverClose(); return wRetVal; } /* -------------------------------------------------------------------- */ graphic_init() { int driver,mode,char_size; driver=EGA; mode=EGAHI; initgraph(&driver,&mode,""); setactivepage(0); setvisualpage(0); setcolor(0); setbkcolor(15); settextstyle(SMALL_FONT,HORIZ_DIR,6); return 0; }