/***************************************************************************** * C LANGUAGE SAMPLE 1: 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 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]; 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 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 - aio8drv driver entry routine. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * *****************************************************************************/ unsigned setup(void) { unsigned int Address; unsigned I,status; clrscr(); puts(" Sample 1 : 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."); puts("\nChannel 0 is configured as a reference junction and channel 1 is "); puts("configured as a 't' type thermocouple. All others are direct.\n"); Address=AskForBaseAddress(0x350); clrscr(); puts("\n\n\nBoard Configuration:\n"); printf(" -- Base Address is %X hex\n",Address); puts(" -- Jumper IRQ5 should be installed (required)"); puts(" -- Jumper EXT should be installed (required)"); puts(" -- All remaining jumper settings are irrelevant"); puts("\n\n\n"); puts("Please press any key to continue."); getch(); params[0] = Address; /* starting board address */ params[1] = 1; /* manual configuration mode */ params[2] = 0; /* AIM 16 in programmable gains */ task = 0; status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ /* clear the point list */ task = 11; params[0] = 2; status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ /* assign the first 16 point addresses to point list */ task = 5; params[0] = 0; params[1] = 15; status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ /* assign a gain code of 5 to point address 1, this is gain of 200 for "t" type thermocouple */ task = 4; params[0] = 1; params[1] = 1; params[2] = 5; status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ /* function assignment for reference junction to point address 0 */ task = 10; params[0] = 2; params[1] = 0; params[2] = 'T'; params[3] = 'F'; status = call_driver(); if (status > 0) return(status); /* if status > 0 then error */ /* function assignment for type "t" thermocouple to point address 1 */ task = 10; params[0] = 2; params[1] = 1; params[2] = 't'; params[3] = 'F'; status = call_driver(); 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 */ printf("\n\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 */