/**************************************************************************** * C LANGUAGE SAMPLE: SAMPLE3.C * * * * This is a demonstration program to be used with the AD8 A/D * * board. The program will prompt for a D/A channel and a digital value * * to output. Entering a channel > 1 exits the program. * * * * This program demonstrates the use of task 0 to initialize the driver * * and task 3 to perform D/A conversions. * * * * Set the IRQ jumper to IRQ5. * * 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() { 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 channel,digital; unsigned int Address; clrscr(); printf(" SAMPLE3.C : AD8-16 D/A Output\n\n"); printf("This is a demonstration program to be used with the AD8 A/D board.\n"); printf("The program will prompt for a D/A channel and a digital value \n"); printf("to output. Entering a channel > 1 exits the program.\n\n"); Address=AskForBaseAddress(0x350); clrscr(); printf("\n\n\nBoard Configuration:\n\n"); printf(" -- The Base Address is %X hex\n",Address); printf(" -- Jumper IRQ5 should be installed (required)\n"); printf(" -- Differential mode inputs needed (required)\n"); printf(" -- All other jumper settings are irrelevant.\n\n\n\n"); printf("\nPress 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 conversion */ clrscr(); gotoxy(1,7); printf("Enter DAC number ( Press 0 or 1; press any other key to exit):"); gotoxy(1,9); printf(" Enter number of digital counts:"); task=3; /* Analog Output Task */ while (statcode == 0) /* loop until driver error */ { gotoxy(63,7); scanf("%d",&channel); /* fetch D/A number */ if (channel > 1) { clrscr(); break; /* if not 0 or 1 then exit */ } gotoxy(63,9); scanf("%d",&digital); /* fetch digital value */ param[0] = channel; param[1] = digital; call_driver(); /* go set the DAC */ }/* end while */ } /* end main */