/***************************************************************************** * C LANGUAGE SAMPLE 3: SAMPLE1.C * * * * This is a demonstration program to be used with the AIO8 A/D card. * * The program will display sixteen channels of data polled from the * * board using the AIO8DRVC.OBJ driver module supplied with the card. * * The program assumes an AIM-16 connected to channel 0 of the A/D. * * This program is identical to sample 1 except that the auto configuration * * option is used. The contents of the setup.cfg file is used. * * This program must be built using the large model. * * * * LAST MODIFICATION: 2/4/98 * * * *****************************************************************************/ #include #include #include #include #include #include "aio8drvc.h" /* These variables MUST be declared as global. They are the ones whose offsets are passed to the AIO8DRV routine. If they are not global then the driver will not find their segment. */ unsigned pntbuf[20],statcode,task; int datbuf[20],params[5]; /***************************************************************************** * FUNCTION: call_driver -- local routine * * * * PURPOSE: Performs the call to the driver module. * * * * INPUT: None. * * * * CALLS: aio8drv - entry point to driver module. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * *****************************************************************************/ unsigned call_driver(void) { aio8drv(FP_OFF(&task),FP_OFF(params),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."); return(statcode); } else return(0); } /* end call_driver */ /***************************************************************************** * FUNCTION: setup -- local routine * * * * PURPOSE: Sets up the driver module. * * * * INPUT: None. * * * * CALLS: call_driver - entry point for the driver. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * *****************************************************************************/ unsigned setup(void) { unsigned I,status; clrscr(); puts(" Sample 3 : AIO8 "); puts("\n"); puts("This sample reads the sixteen analog inputs from an AIM-16 attached"); puts("to channel 0 of the AIO8 and displays them for you.\n\n"); puts("Board Configuration Requirements:\n"); puts(" -- BASE ADDRESS: as assigned in SETUP.CFG file"); puts(" -- All needed jumper settings are explained in the SETUP.CFG file\n\n\n"); puts("Please press any key to continue."); getch(); task = 0; params[1] = 0; /* AUTO configuration mode */ status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ /* now set the sample and hold settle time */ task = 11; params[0] = 5; params[1] = 50; status = call_driver(); /* call routine to call ext module */ return(status); } /* end setup */ /***************************************************************************** * FUNCTION: get_readings -- local routine * * * * PURPOSE: Reads the 16 A/D channels and displays them on the screen. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver module. * * * * OUTPUT: Returns the error code supplied by the driver routine. * *****************************************************************************/ unsigned get_readings(void) { unsigned channel,gain,I,status; double data; /* now reset the task list index */ task = 11; params[0] = 1; status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ task = 8; params[0] = FP_OFF(datbuf); /* offset to data buffer */ params[1] = FP_OFF(pntbuf); /* offset to point bufffer */ params[2] = 16; /* make 16 readings from point list */ status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ /* now if OK list the data to the screen */ clrscr(); printf("\n CHANNEL VALUE GAIN\n"); printf(" ------- ------ -----\n"); for (I = 0;I < 16;I++) { channel = (pntbuf[I] & 0xff00) / 256; /* upper bits contain ch number */ gain = pntbuf[I] &0xff; data = datbuf[I] * 0.1; /* scale millivolts to volts */ printf("%10i%11.3f%7i\n",channel,data,gain); } return(0); } /* end get_readings */ /***************************************************************************** * FUNCTION: main -- local routine * * * * PURPOSE: Controls program flow, detects when user is ready to exit. * * * * INPUT: None. * * * * CALLS: setup - set up program and drivers. * * get_readings - read the A/D channels and display. * * * * OUTPUT: None. * *****************************************************************************/ void main(void) { unsigned status; char ch; status = setup(); /* set up program and the driver */ if (status != 0) return; /* is status > 0 then board error */ do { /* display current values for the 8 channels */ status = get_readings(); if (status != 0) return; /* if status > 0 then error */ /* check for program exit */ printf("\nPress E to exit the program. Press any other key to rescan for data..."); while (!kbhit); /* wait for key press */ ch = getch(); /* read the char */ } while (ch != 'E' && ch != 'e'); } /* end main program */