/**************************************************************************** * C LANGUAGE SAMPLE: SAMPLE4.C * * * * This is a demonstration program to be used with the AD8 A/D * * board. The program will prompt for a counter number, a counter mode * * and a load divisor value. A channel number greater than 2 exits. * * * * This program demonstrates the use of task 0 to initialize the driver * * and task 5 to manipulate the counter. * * * * Set the IRQ jumper to IRQ5. * * The counter clk jumper should be installed. * * 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: Sets up and controls the counters. * * * * INPUT: None. * * * * CALLS: call_driver, * * * * OUTPUT: None. * * * ****************************************************************************/ void main(void) { int counter,mode,loadvalue; unsigned int Address; clrscr(); printf(" SAMPLE4.C : AD8-16 Counter Operations\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 counter number, a counter mode\n"); printf("and a load divisor value. A channel number greater than 2 exits. \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(" -- Counter clock jumper should be installed (required)\n"); printf(" -- All other jumper settings are irrelevant.\n\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(); clrscr(); gotoxy(1,7); printf("Enter counter number (press 0 thru 2; press any other key to exit):"); gotoxy(1,9); printf(" Enter the counter mode(0 - 5):"); gotoxy(1,11); printf(" Enter the counter load value:"); task=5; /* counter Output Task */ while (statcode == 0) /* loop until driver error */ { gotoxy(68,7); scanf("%d",&counter); /* fetch counter number */ if (counter > 2) /* if not 0 thru 2 then exit */ { clrscr(); break; } gotoxy(68,9); scanf("%d",&mode); /* fetch counter mode */ gotoxy(68,11); scanf("%d",&loadvalue); /* fetch counter load value */ param[0] = counter; param[1] = mode; param[2] = loadvalue; call_driver(); /* go set the counter*/ }/* end while */ } /* end main */