/**********************************************************************/ /* This program is developed by Borland C++ 3.1 */ /***********************************************************************/ /* Demo 6: two board P180X cards M_FUN_1 demo. */ /***********************************************************************/ #define MYLIB #include "P180X.H" int iLine; float fAdBuf[510]; WORD wDaFreq0,wDaFreq1; WORD wAdClk0,wAdClk1; 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 wDaWave=80,wAdNum=510; float fDaMagnitude=2.5; float fSampleRate0,fSampleRate1; 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"); /* The D/A output wave form generator is a machine dependent function. */ /* The D/A output frequency: */ /* for Pemtium-120 -> D/A output freqency=1.8M/wDaFreq */ /* for Pemtium-133 -> D/A output freqency=2.0M/wDaFreq */ /* suggestion: wDaFreq=90 */ printf("(1st Card)Please Enter the Frequency for D/A(suggestion 90) -> "); scanf("%d",&wDaFreq0); /* Enter wAdClk, the A/D sampling rate is 8M/wAdClk */ /* suggestion: wAdClk=24 */ printf("(1st Card)Please Enter wAdClk(suggestion 24) -> "); scanf("%d",&wAdClk0); printf("\n"); fSampleRate0=8000.0/wAdClk0; /* A/D is fSampleRate Khz */ printf("(2nd Card)Please Enter the Frequency for D/A(suggestion 90) -> "); scanf("%d",&wDaFreq1); /* Enter wAdClk, the A/D sampling rate is 8M/wAdClk */ /* suggestion: wAdClk=24 */ printf("(1st Card)Please Enter wAdClk(suggestion 24) -> "); scanf("%d",&wAdClk1); printf("\n"); fSampleRate1=8000.0/wAdClk1; /* A/D is fSampleRate Khz */ graphic_init(); cleardevice(); setcolor(RED); /************** M1 Function ****************************/ /*--------- To Active First P180X Card --------------------*/ P180X_ActiveBoard( 0 ); for(i=0; i<510; i++) fAdBuf[i]=0.0; wRetVal=P180X_M_FUN_1(wDaFreq0,wDaWave,fDaMagnitude,wAdClk0,wAdNum, 0,fAdBuf,-10.0,+10.0); if (wRetVal==0) { sprintf(cShow,"1st Card: P180X_M_FUN_1 OK, Sample Rate is %7.3fK",fSampleRate0); outtextxy(10,10,cShow); } else { cleardevice(); closegraph(); putch(0x07); printf("1st Card: P180X_M_FUN_1 ERROR, return=%x\n\n",wRetVal); exit(0); } for(i=0; i<501; i++) /* channel 0's data and its wave form */ wPlot0[i]=100+(WORD)(fAdBuf[i]*16.0); for(i=0; i<500; i++) /* plot channel 0's wave form */ line(10+i,wPlot0[i],10+i+1,wPlot0[i+1]); /*--------- To Active Second P180X Card --------------------*/ P180X_ActiveBoard( 1 ); for(i=0; i<510; i++) fAdBuf[i]=0.0; wRetVal=P180X_M_FUN_1(wDaFreq1,wDaWave,fDaMagnitude,wAdClk1,wAdNum, 0,fAdBuf,-10.0,+10.0); if (wRetVal==0) { sprintf(cShow,"2nd Card: P180X_M_FUN_1 OK, Sample Rate is %7.3fK",fSampleRate0); outtextxy(10,220,cShow); } else { cleardevice(); closegraph(); putch(0x07); printf("2nd: P180X_M_FUN_1 ERROR, return=%x\n\n",wRetVal); exit(0); } for(i=0; i<501; i++) /* channel 0's data and its wave form */ wPlot0[i]=300+(WORD)(fAdBuf[i]*16.0); for(i=0; i<500; i++) /* plot channel 0's wave form */ line(10+i,wPlot0[i],10+i+1,wPlot0[i+1]); getch(); cleardevice(); closegraph(); P180X_DriverClose(); return 0; } /* -------------------------------------------------------------------- */ 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; }