/**********************************************************************/ /* This program is developed by Turbo C 2.0 */ /***********************************************************************/ /* Demo 10: two P180X card M_FUN_3 demo. */ /* First Card: To acquire A/D CH:0, CH:1, CH:2 250 times. */ /* Second Card: To acquire A/D CH:0, CH:1, CH:2 250 times. */ /***********************************************************************/ #define MYLIB #include "P180X.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 is the data for CH:1 */ WORD wDaFreq=90; /* D/A output frequency is 1.8M/wDaFreq. */ WORD wAdClk=24; /* 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=80; float fDaMagnitude=(double)2.5,dfAdFrequency; WORD wAddrTimer,wAddrCtrl,wAddrDio,wAddrAdda; /* 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<=1 ) { putch(0x07); putch(0x07); putch(0x07); printf("Please install two P180X cards 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 1234H | Digital Input -> %04xH\n",wDIOdata); printf("----------------------------------------------------------\n"); printf("The Second P180X Card...\n"); P180X_ActiveBoard( 1 ); P180X_Do(0x5678); /* Digital output */ P180X_Di(&wDIOdata); /* Digital input */ printf("Digital Output -> 5678H | Digital Input -> %04xH\n",wDIOdata); printf("\n\n"); printf("Hit any key to continue...\n"); getch(); /************** M3 Function ****************************/ graphic_init(); cleardevice(); setcolor(RED); /*--------- To Active First P180X Card --------------------*/ sprintf(cShow,"First P180X Card: CH0,CH1,CH2"); outtextxy(10,10,cShow); P180X_ActiveBoard( 0 ); 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=P180X_M_FUN_3(wDaFreq,wDaWave,fDaMagnitude,wAdClk,wAdNum, wChannel,wConfigCode,fAdBuf,-10.0,+10.0); 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]); } /**********************************************************/ /*--------- To Active Second P180X Card -------------------*/ sprintf(cShow,"Second P180X Card: CH0,CH1,CH2"); outtextxy(300,10,cShow); P180X_ActiveBoard( 1 ); 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=P180X_M_FUN_3(wDaFreq,wDaWave,fDaMagnitude,wAdClk,wAdNum, wChannel,wConfigCode,fAdBuf,-10.0,+10.0); for(i=0; i<250; i++) /* channel 0's data and its wave form */ { wPlot0[i]=60+(WORD)(fAdBuf[i]*12.0); } for(i=0; i<249; i++) /* plot channel 0's wave form */ { line(300+i,wPlot0[i],300+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(300+i,wPlot0[i],300+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(300+i,wPlot0[i],300+i+1,wPlot0[i+1]); } getch(); cleardevice(); closegraph(); P180X_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); }