/***************************************************************************** * C LANGUAGE SAMPLE 1: SAMPLE1.C * * * * This is a demonstration program to be used with the AD12-8G A/D board. * * The program will display channels of data polled from the board using the* * A12GDRV driver module supplied with the board. This sample expects that * * a sub-multiplexer board with programmable gains is attached to channel 0.* * The driver uses the three counters to set the gain on the mux board. * * This program must be built using the large model. * * * * LAST MODIFICATION: 2/4/98 * * * *****************************************************************************/ #include #include #include #include #include #include "a12gdrvc.h" #ifndef FALSE #define FALSE 0 #define TRUE !FALSE #endif /* These variables MUST be declared as global. They are the ones whose offsets are passed to the A12GDRV routine. If they are not global the driver will not find their segment. */ unsigned pntbuf[200],statcode,task; int datbuf[200],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 package. * * * * INPUT: None. * * * * CALLS: a12gdrv - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * *****************************************************************************/ unsigned call_driver() { char Input_Char; statcode = 0; a12gdrv(FP_OFF(&task),FP_OFF(params),FP_OFF(&statcode)); /* this section checks for an error code */ if (statcode > 0) { printf("TASK %i has returned an error code of %i.\n",task,statcode); printf("Press 'C' to continue, any other key to exit.\n"); Input_Char = toupper(getch()); printf("\n"); if (Input_Char == 'C') statcode = 0; } else return(statcode); } /* end call_driver */ /***************************************************************************** * FUNCTION: setup -- local routine * * * * PURPOSE: Sets up the driver package, with the first 16 point addresses. * * * * INPUT: None. * * * * CALLS: call_driver() - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * *****************************************************************************/ unsigned setup(Address) { unsigned I,status; task = 0; params[0] = Address; /* starting board address */ params[1] = 5; /* IRQ5 --does not matter for this sample */ params[2] = 1; /* programmable gain sub-multiplexer mode */ status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ task = 11; params[0] = 2; /* clear the point list */ status = call_driver(); if (status > 0) return(status); /* place the first 17 point addresses in the point list */ task = 5; params[0] = 0; params[1] = 16; status = call_driver(); if (status > 0) return(status); /* assign gain code 0 to point address 0, gain code 1 to p.a. 1 etc */ task = 4; for (I = 0;I <= 7;I++) { task = 4; params[0] = I; params[1] = I; params[2] = I; status = call_driver(); /* call routine to call ext module */ if (status > 0) return(status); /* if status > 0 then error */ } /* set the settle time constant */ task = 11; params[0] = 4; params[1] = 25; 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: Read 17 channels from the point list and display them. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * *****************************************************************************/ unsigned get_readings() { unsigned gain,channel,I,status; int *temp1; unsigned *temp,offpntbuf,offdatbuf; /* 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 pnt buffer 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 buffer */ params[2] = 17; /* make 17 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 */ clrscr(); 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 */ gain= pntbuf[I] & 0x00ff; /* lower bits contain ch number */ printf(" %3i %5i %3i\n",channel,datbuf[I],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 int Address; unsigned status; char ch; clrscr(); puts(" SAMPLE1.C : AD12-8G DEMONSTRATION DATA ACQUISITION\n\n"); puts("This sample will scan all sixteen channels of a submultiplexer board"); puts("on channel 0, and display these points along with channel 1 (point 16)."); puts("This sample uses the programmable gains on the submultiplexer board.\n"); Address=AskForBaseAddress(0x350); clrscr(); printf("\n\n\nBoard Configuration:\n\n"); printf(" -- The Base Address is %X hex\n",Address); printf(" -- Programmable gains on submultiplexer board needed (required)\n"); printf(" -- All other jumper settings are irrelevant.\n\n\n"); puts("\nPress any key to run the program."); getch(); status = setup(Address); /* set up program and the driver */ if (status != 0) return; /* is status > 0 then board error */ do { status = get_readings(); /* display current A/D values */ if (status != 0) return; /* if status > 0 then error */ /* check for program exit */ printf("\n\nPress 'E' to exit 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 */