/***********************************************************************/ /* This program is developed by Turbo C 2.0 */ /***********************************************************************/ /* Demo 8: two P1602 card M_FUN_2 demo. */ /***********************************************************************/ #define MYLIB #include "P1602.H" int iLine; float fAdBuf[510]; WORD wAdClk; WORD wDa[320],wAd[510]; WORD wPlot0[512]; /* transformed into wave form */ int main() { int i,j; char cShow[80]; WORD wBoards,wRetVal; WORD wDIOdata; DWORD dwExact,dwOKs,dwErrors,dwScanCount,dwP1,dwP2,dwStatus; double 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<=1 ) { putch(0x07); putch(0x07); putch(0x07); printf("Please install two P1602 cards 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); printf("----------------------------------------------------------\n"); printf("The Second P1602 Card...\n"); P1602_ActiveBoard( 1 ); P1602_Do(0x5678); /* Digital output */ P1602_Di(&wDIOdata); /* Digital input */ printf("Digital Output -> 5678H | Digital Input -> %04xH\n",wDIOdata); printf("\n\n"); printf("Hit any key to continue...\n"); getch(); graphic_init(); cleardevice(); /************** M2 Function ****************************/ for(i=0; i<64; i++) wDa[i]=0x800-i*16; for(i=0; i<64; i++) wDa[i+64]=0x800-(64-i)*16; for(i=0; i<64; i++) wDa[i+64*2]=0x800; for(i=0; i<64; i++) wDa[i+64*3]=0x800-64*8; for(i=0; i<64; i++) wDa[i+64*4]=0x800; /*--------- To Active First P1602 Card -------------------*/ setcolor(RED); P1602_ActiveBoard( 0 ); for (i=0; i<510; i++) wAd[i]=0; wRetVal=P1602_M_FUN_2(320,25,wDa,80,510,0,wAd); if(wRetVal==0) { sprintf(cShow,"1st Card: P1602_M_FUN_2 OK."); outtextxy(10,10,cShow); } else { cleardevice(); closegraph(); putch(0x07); printf("2nd: P1602_M_FUN_2 ERROR, return=%x\n\n",wRetVal); exit(0); } for(i=0; i<501; i++) /* channel 0's data and its wave form */ wPlot0[i]=80-( (int)wAd[i]/256 ); 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 P1602 Card --------------------*/ P1602_ActiveBoard( 1 ); for (i=0; i<510; i++) wAd[i]=0; wRetVal=P1602_M_FUN_2(320,25,wDa,80,510,0,wAd); if(wRetVal==0) { sprintf(cShow,"2nd Card: P1602_M_FUN_2 OK."); outtextxy(10,200,cShow); } else { cleardevice(); closegraph(); putch(0x07); printf("2nd: P1602_M_FUN_2 ERROR, return=%x\n\n",wRetVal); exit(0); } for(i=0; i<501; i++) /* channel 0's data and its wave form */ wPlot0[i]=250-((int)wAd[i]/256); 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(); P1602_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; }