/**************************************************************************** * C LANGUAGE SAMPLE: SAMPLE1.C * * * * The program will perform constant differential conversions of * * all eight channels and display the results. * * * * This program demonstrates the use of task 0 to initialize the driver * * and task 1 to perform A/D conversions. * * * * Set the IRQ jumper to IRQ5. * * The differential/single ended jumper should be installed to DIF. * * 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(void) { 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: 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(" SAMPLE1.C : AD8-16, Polling A/D Data\n\n"); printf("The program will perform constant differential conversions of\n"); printf("all eight channels 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(" -- Differential mode inputs needed (required)\n"); printf(" -- Jumper IRQ5 should be installed (required)\n"); printf(" -- All remaining jumper settings are irrelevant.\n\n\n\n"); printf("Press any key to continue, or press E to exit the program.\n"); if(toupper(getch())=='E') return; task=0; /*Setup driver */ param[0]=Address; /*Assign the Base Address */ param[1]=0; /*differential mode inputs, 1 would be S/E*/ param[2]=1; /*bipolar mode, 0 would be unipolar */ param[3]=5; /*IRQ line jumpered on board */ call_driver(); /* Begin the acquisition */ clrscr(); task=1; /*Analog Input Task */ param[1]=1; /*+/- 5V range, 0 would be +/-127mV */ for(i=0;(!kbhit());i++,i%=8) /*loop until key is pressed, i=0..7 */ { param[0]=i; /*channel number to be scanned */ call_driver(); gotoxy(1,6+i); printf("Channel:%2u value:%4i ",i,param[2]); gotoxy(1,20); printf("\n\n\nPress any key to terminate the program"); }/* end for */ if (statcode == 0) clrscr(); } /* end main */