/**************************************************************************** * C LANGUAGE SAMPLE: SAMPLE2.C * * * * This is a demonstration program to be used with the AD8 A/D * * board. The program will perform 80 interrupt driven acquisitions on * * channel 0 and display the results. * * * * This program demonstrates the use of task 0 to initialize the driver * * and task 7 to perform and monitor the interrupt process. * * * * Set the IRQ jumper to IRQ5. * * The differential/single ended jumper should installed to SE. * * This program must be built using the large model. * * * * LAST MODIFICATION: 2/4/98 * * * ****************************************************************************/ #include #include #include #include #include #include "ad8drvc.h" #ifndef FALSE #define FALSE 0 #define TRUE !FALSE #endif /* These are the parameters that are passed to the driver, they must be global or the driver will not find their segment. */ int param[5],task,statcode; int buffer[100]; unsigned AskForBaseAddress(unsigned int OldOne) { char msg[7]; int NewOne = 0, Success = 0, Dummy; int AddrInputPosX, AddrInputPosY; puts("\nPlease enter the Base Address for your card (in hex)"); printf("or press ENTER for %X.\n>", OldOne); AddrInputPosX = wherex(); AddrInputPosY = wherey(); do { gotoxy(AddrInputPosX, AddrInputPosY); clreol(); msg[0] = 5; msg[1] = 0; cgets(msg); sscanf(msg + 2, "%x", &NewOne); Success = 1; Dummy = NewOne; if (msg[1] == 0) { gotoxy(AddrInputPosX, AddrInputPosY); printf("%X", OldOne); Success = 1; Dummy = OldOne; } } while(!Success); return (Dummy); } /* end of AskForBaseAddress */ /**************************************************************************** * FUNCTION: call_driver -- local routine * * * * PURPOSE: Performs the call to the driver package. * * * * INPUT: None. * * * * CALLS: ad8drv - entry point to driver package. * * * * OUTPUT: None. * * * ****************************************************************************/ void call_driver() { ad8drv(FP_OFF(&task),FP_OFF(param),FP_OFF(&statcode)); /* this section checks for an error code */ if (statcode > 0) { printf("A status error code of %i was detected.\n",statcode); printf("Program terminated."); } } /* end call_driver */ /**************************************************************************** * FUNCTION: display_data -- local routine * * * * PURPOSE: Displays the data from the buffer after interrupts. * * * * INPUT: None. * * * * CALLS: None. * * * * OUTPUT: None. * * * ****************************************************************************/ void display_data(void) { int k,j; clrscr(); printf("\n\n\n\n\n"); for(j=0;j<80;j+=10) { for(k=0;k<10;k++) printf("%6i",buffer[j+k]); printf("\n"); } } /* end display_data */ /**************************************************************************** * FUNCTION: main -- local routine * * * * PURPOSE: Performs data acquisition using interrupts. * * * * INPUT: None. * * * * CALLS: call_driver, * * * * OUTPUT: None. * * * ****************************************************************************/ void main(void) { int i; unsigned int Address; clrscr(); printf(" SAMPLE2.C : Interrupt Driven A/D Data\n\n"); printf("This is a demonstration program to be used with the AD8 A/D board.\n"); printf("The program will perform 80 interrupt driven acquisitions on\n"); printf("channel 0 and display the results.\n\n"); Address=AskForBaseAddress(0x350); clrscr(); printf("\n\n\nBoard Configuration:\n\n"); printf(" -- The Base Address is %X hex\n",Address); printf(" -- Jumper IRQ5 should be installed (required)\n"); printf(" -- S.E/DIFF: Single Ended (bottom pins) needed (required)\n"); printf(" -- All other jumper settings are irrelevant.\n\n\n\n"); printf("\nPress any key to continue, or press E to exit.\n"); if(toupper(getch())=='E') return; task=0; /* initialize driver */ param[0]=Address; /* Assign the Base Address */ param[1]=1; /* 1 = single ended -- 0 = differential*/ param[2]=1; /* bipolar mode -- 0 would be unipolar */ param[3]=5; /* IRQ line as jumpered on the board */ call_driver(); if (statcode > 0) return; task=7; param[0]=1; /* subtask 1, setup and begin */ param[1]=80; /* number of scans desired */ param[2]=0; /* channel we wish to scan */ param[3]=1; /* gain code we want for the readings */ param[4]=FP_OFF(buffer); call_driver(); if (statcode > 0) return; /* loop until driver indicates completion of readings */ task=7; param[0]=2; /* select subtask 2, check for completion of interrupts */ param[1]=1; /* number of conversion left, is returned here. */ while(param[1]>0) { call_driver(); /* sets param[1] to number of scans remaining */ if (statcode > 0) break; } if (statcode == 0) display_data(); printf("\n\n\n\nPress any key to exit the program.\n"); getch(); } /* end main */