/***************************************************************************** * SAMPLE5.C : DIGITAL OUTPUT * * * * This is a demonstration program to be used with the AD12-16 A/D * * board. The program will prompt the user for a digital value between 0 * * 15. The program will output this value to digital output bits and then * * read it back on the digital input channels. This demos setting the * * digital output bits(task 13)and reading the digital input bits(task 14). * * This program must be built using the large model. * * * * The board should be set as follows: * * -- IRQ5 is used for interrupts * * -- Polarity set to bipolar * * -- DMA channel 1 * * -- On board clock set to 1 MHz * * Also, the following jumps should be installed. * * -- OP0 pin 23 to IP0 pin 25 * * -- OP1 pin 4 to IP1 pin 6 * * -- OP2 pin 22 to IP2 pin 24 * * -- OP3 pin 3 to IP3 pin 5 * * * * LAST MODIFICATION: 2/3/98 * * * *****************************************************************************/ #include #include #include #include #include #include "a16drvc.h" /* These variable MUST be declared as global. They are the ones whose offsets are passed to the A16DRV routine. If they are not global then the driver will not find their segment. */ unsigned pntbuf[100],statcode,task; int datbuf[100],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: a16drv - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * *****************************************************************************/ unsigned call_driver() { unsigned *temp1,offtask,offparams,offstatcode; int *temp; /* this section extracts the offset of the parameters that we will pass to the assembly driver */ temp1 = &task; offtask = FP_OFF(temp1); /* offset of task number */ temp = params; offparams = FP_OFF(temp); /* offset of param list */ temp1 = &statcode; offstatcode = FP_OFF(temp1); /* offset of status code */ statcode = 0; a16drv(offtask,offparams,offstatcode); /* call the driver */ /* 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 package to read channel 0. * * * * 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; /* initialize the board */ params[0] = Address; /* starting board address */ params[1] = 5; /* IRQ5 */ params[2] = 1; /* DMA channel 1 */ task = 0; status = call_driver(); /* call driver */ return(status); } /* end setup */ /***************************************************************************** * FUNCTION: get_readings -- local routine * * * * PURPOSE: Prompts for a voltage, writes to the D/A and reads it back. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * *****************************************************************************/ unsigned get_readings() { unsigned I,status; clrscr(); /* fetch a voltage to output from the console */ printf("Enter a digital output value(0-15):"); scanf("%d",params); /* set digital output to this value */ task = 13; status = call_driver(); if (status > 0) return(status); /* exit if error */ for (I = 0;I < 2000;I++); /* now read the digital input lines */ task = 14; status = call_driver(); if (status > 0) return(status); /* exit if error */ /* now if OK compute and list the data to the screen */ printf("\nThe value read back is: %3d\n",params[0]); 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(); printf( " SAMPLE5.C : DIGITAL OUTPUT \n\n" " This is a demonstration program to be used with the AD12-16 A/D \n" " board. The program will prompt the user for a digital value between 0 \n" " 15. The program will output this value to digital output bits and then \n" " read it back on the digital input channels. This demos setting the \n" " digital output bits(task 13)and reading the digital input bits(task 14).\n" " \n"); Address=AskForBaseAddress(0x350); clrscr(); printf( "\n\n\n Board Configuration Requirements: \n\n" " -- Base address is %x hex \n" " -- IRQ5 is used for interrupts \n" " -- Polarity set to bipolar \n" " -- DMA channel 1 \n" " -- On board clock set to 1 MHz \n\n\n" " Also, the following jumps should be installed. \n\n" " -- OP0 pin 23 to IP0 pin 25 \n" " -- OP1 pin 4 to IP1 pin 6 \n" " -- OP2 pin 22 to IP2 pin 24 \n" " -- OP3 pin 3 to IP3 pin 5 \n",Address); puts("\n All remaining jumper settings are irrelevant."); printf("\n\n\nPress any key to continue, or E to exit."); ch=getch(); clrscr(); status = setup(Address); /* set up program and the driver */ if (status != 0) return; /* is status > 0 then board error */ while (ch != 'E' && ch != 'e') { 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 */ } clrscr(); } /* end main program */