/***********************************************************************/ /* This program is developed by Turbo C 2.0 */ /***********************************************************************/ /* DEMO 13: P1602_Card0 Function demo. */ /* ==> to sacn all 32 channels with various sampling rate, and */ /* display wave form for CH:0, CH:1 and CH:2. */ /* The sampling rate is 8M/div, where 'div' is an inputed number. */ /***********************************************************************/ #define MYLIB #include "P1602.H" #define DATACOUNT 200 /* how many data is scan for a A/D channel */ WORD wPlot0[DATACOUNT]; /* transformed into wave form */ WORD wPlot1[DATACOUNT]; /* transformed into wave form */ WORD wPlot2[DATACOUNT]; /* transformed into wave form */ int main() { int i,j; WORD wBoards,wRetVal; WORD wDIOdata; WORD wChannelStatus[32],wChannelConfig[32]; char cShow[80]; DWORD dwExact,dwOKs,dwErrors,dwScanCount,dwP1,dwP2,dwStatus; WORD wDiv; 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); /* Enter divider, the A/D sampling rate is 8M/divider */ printf("The scanning sampling rate is 8M/divider.\n"); printf("when divider=80, then sampling rate is 8M/80=100K\n"); printf("Please Enter the divider -> "); scanf("%d",&wDiv); graphic_init(); cleardevice(); /************** P1602_Card0 Function starting ***********************/ for(i=0; i<32; i++) { /* the status for each channel, 1: to scan 0: no scan */ wChannelStatus[i]=0; /* the config code for each channel */ wChannelConfig[i]=0; } for(i=0; i<32; i++) /* add all channel to scan */ wChannelStatus[i]=1; setcolor(RED); sprintf(cShow,"<- The Wave Form of CH:0"); outtextxy(150,100,cShow); sprintf(cShow,"<- The Wave Form of CH:1"); outtextxy(150,200,cShow); sprintf(cShow,"<- The Wave Form of CH:2"); outtextxy(150,300,cShow); dwExact=0; dwScanCount=0; for (;;) { setcolor(RED); sprintf(cShow,"Scan -> %2d",dwScanCount); outtextxy(5,20,cShow); P1602_ActiveBoard( 0 ); /* prepare StartScan */ wRetVal=P1602_Card0_StartScan(wDiv,wChannelStatus,wChannelConfig,DATACOUNT); if( wRetVal==NoError ) { sprintf(cShow,"1st card: P1602_Card0_StartScan OK."); outtextxy(5,5,cShow); } else { cleardevice(); closegraph(); putch(0x07); printf("P1602_Card0_StartScan Function Error !!!, wRetVal -> %2d",wRetVal); exit(0); } wRetVal=P1602_Card0_ReadData(); if(wRetVal==0) { setcolor(WHITE); /* set as blackground color */ /* erasing previos ploted wave form */ for(i=0; i<50; i++) /* channel 0's wave form */ { line(10+i,wPlot0[i],10+i+1,wPlot0[i+1]); } for(i=0; i<50; i++) /* channel 1's wave form */ { line(10+i,wPlot1[i],10+i+1,wPlot1[i+1]); } for(i=0; i<50; i++) /* channel 1's wave form */ { line(10+i,wPlot2[i],10+i+1,wPlot2[i+1]); } sprintf(cShow,"Exact -> %2d",dwExact); outtextxy(5,40,cShow); /********** ploting the CH:0 & CH:1 & CH:2 wave form *********/ dwExact++; setcolor(RED); for(i=0; i<51; i++) /* channel 0's data and its wave form */ { wPlot0[i]=110-(int)wBuf1[i]/256; } for(i=0; i<50; i++) /* plot channel 0's wave form */ { line(10+i,wPlot0[i],10+i+1,wPlot0[i+1]); } /*-------------------*/ for(i=0; i<51; i++) /* channel 1's data and its wave form */ { wPlot1[i]=210-(int)wBuf1[DATACOUNT+i]/256; } for(i=0; i<50; i++) /* plot channel 1's wave form */ { line(10+i,wPlot1[i],10+i+1,wPlot1[i+1]); } /*-------------------*/ for(i=0; i<51; i++) /* channel 2's data and its wave form */ { wPlot2[i]=300-(int)wBuf1[2*DATACOUNT+i]/256; } for(i=0; i<50; i++) /* plot channel 2's wave form */ { line(10+i,wPlot2[i],10+i+1,wPlot2[i+1]); } sprintf(cShow,"Exact -> %2d",dwExact); outtextxy(5,40,cShow); } else { cleardevice(); closegraph(); putch(0x07); printf("P1602_Card0_ReadData() Error !!!, wRetVal -> %2d",wRetVal); exit(0); } setcolor(WHITE); sprintf(cShow,"Scan -> %2d",dwScanCount); outtextxy(5,20,cShow); dwScanCount++; if( kbhit() ) break; P1602_Card0_Stop(); } P1602_Card0_Stop(); 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; }