/**************************************************************************** * C LANGUAGE SAMPLE 3: SAMPLE3.C * * * * This is a demonstration program to be used with the AD12-8 A/D * * board and an AIM-16. The program will display the set of data channels * * described by the SETUP.CFG file created by the setup programs. The data * * channels are polled from the board using the A12DRVC.OBJ driver module * * supplied with the board. * * This program must be built using the large model. * * * * LAST MODIFICATION: 2/3/98 * * * ****************************************************************************/ #include #include #include #include #include #include #include "a12drvc.h" /* These variable MUST be declared as global. They are the ones whose offsets are passed to the A12DRV routine. If they are not global then the driver will not find their segment. */ /* The 200 array size, below, is only for convenience, as the largest size that might be needed in this program is 128 points of data. */ unsigned pntbuf[200],statcode,task; int datbuf[200],params[5]; unsigned int ADDRESS; /**************************************************************************** * FUNCTION: call_driver -- local routine * * * * PURPOSE: Performs the call to the driver package. * * * * INPUT: None. * * * * CALLS: a12drv - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * ****************************************************************************/ unsigned call_driver() { a12drv(FP_OFF(&task),FP_OFF(params),FP_OFF(&statcode)); /* this section checks for an error code */ if (statcode > 0) { puts("\n"); 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 * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * ****************************************************************************/ unsigned setup() { unsigned I,status; clrscr(); puts(" SAMPLE 3.C : AD12-8"); puts("\n"); puts("This sample reads the analog inputs from the AD12-8 and any"); puts("expansion boards, as determined by the SETUP.CFG file."); puts("\n"); puts("Board Configuration Requirements:"); puts("\n"); puts("PLEASE SEE FILE: SETUP.CFG"); puts("\n"); puts("\n"); ADDRESS = AskForBaseAddress(0x300); /* this is the automatic configuration section */ task = 0; params[1] = 0; // automatic initialization status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ /* this task is only need for faster computers, ie a very fast 286 or 386 */ task = 11; params[0] = 5; params[1] = 300; /* good delay for a 386 25MHz */ status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ return(0); } /* end setup */ /**************************************************************************** * FUNCTION: get_readings -- local routine * * * * PURPOSE: Reads the 8 A/D channels and displays them on the screen. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * ****************************************************************************/ unsigned get_readings() { unsigned channel,I,status,gain,*temp,offpntbuf,offdatbuf; double data; int *temp1; /* 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 */ /* calculate the offset to the buffers so the driver can return the data. datbuf will contain the data read from the channels and pntbuf will contain the channel and gain info. */ temp1 = datbuf; offdatbuf = FP_OFF(temp1); temp = pntbuf; offpntbuf = FP_OFF(temp); task = 8; params[0] = offdatbuf; /* offset to data buffer */ params[1] = offpntbuf; /* offset to point bufffer */ params[2] = 16; /* make 8 readings from point list */ params[3] = 0; /* number of samples returned here */ 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 */ printf("\n CHANNEL VALUE GAIN\n"); printf(" ------- ------ ----\n"); for (I = 0;I <= params[3] - 1;I++) { channel = (pntbuf[I] & 0xff00) / 256; /* upper bits contain ch number */ data = datbuf[I]; gain = pntbuf[I] & 255; printf(" %3i %10.1f %3i\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() { 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 the data..."); while (!kbhit()); /* wait for key press */ ch = getch(); /* read the char */ } while (ch != 'E' && ch != 'e'); } /* end main program */