/**********************************************************************/ /* This program is developed by Microsoft C 5.1 */ /***********************************************************************/ /* DEMO 13: One P1202_Card0 Function demo. */ /* ==> to sacn all 32 channels with various sampling rate, and */ /* display values for channel 0 , channel 1 and channel 2. */ /***********************************************************************/ #define MYLIB #include "P1202.H" #define DATACOUNT 200 // how many data is scan for a A/D channel WORD wPlot0[200]; // transformed into wave form WORD wPlot1[200]; // transformed into wave form WORD wPlot2[200]; // 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; clrscr(); // a clear screen function in P1202MC?.LIB gotoxy(1,1); // initiaing P1202 card and detect how many P1202 card in PC wRetVal=P1202_DriverInit(&wBoards); printf("Threr are %d P1202 Cards in this PC.\n",wBoards); if( wBoards==0 ) { putch(0x07); putch(0x07); putch(0x07); printf("There are no P1202 card in this PC !!!\n"); exit(0); } /* dump every P1202 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); /************** P1202_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; dwExact=0; dwScanCount=0; P1202_ActiveBoard( 0 ); for (;;) { gotoxy(1,9); printf("Scan -> %ld\n",dwScanCount++); // prepare StartScan wRetVal=P1202_Card0_StartScan(wDiv,wChannelStatus,wChannelConfig,DATACOUNT); if( wRetVal==NoError ) { printf("1st card: P1202_Card0_StartScan OK.\n"); } else { putch(0x07); printf("P1202_Card0_StartScan Function Error !!!, wRetVal -> %2d",wRetVal); exit(0); } wRetVal=P1202_Card0_ReadData(); if(wRetVal==0) { /********** show the CH:0 & CH:1 & CH:2 wave form *********/ printf("Channel 0's first 12 data:\n"); for(i=0; i<12; i++) { printf("[%03d]=%04xH ",i,wBuf1[i]); if( i%4==3 ) printf("\n"); } printf("Channel 1's first 12 data:\n"); for(i=0; i<12; i++) { printf("[%03d]=%04xH ",DATACOUNT+i,wBuf1[DATACOUNT+i]); if( i%4==3 ) printf("\n"); } printf("Channel 2's first 12 data:\n"); for(i=0; i<12; i++) { printf("[%03d]=%04xH ",2*DATACOUNT+i,wBuf1[2*DATACOUNT+i]); if( i%4==3 ) printf("\n"); } } else { putch(0x07); printf("P1202_Card0_ReadData() Error !!!, wRetVal -> %2d",wRetVal); exit(0); } if( kbhit() ) break; } P1202_Card0_Stop(); P1202_DriverClose(); return 0; }