#include #include #include #include unsigned int Address; void OutputValue(char CH, unsigned VALUE) { outport(Address + (CH * 2), VALUE); } 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 */ void main(void) { unsigned Channel = 0, Value = 0; char key = 0; clrscr(); puts("Borland C Language Sample for D/A16-16. Version 1.05\r\n\n"); puts("Board Configuration:\n"); puts("-- The Base Address should be set to the address which will be entered."); puts("-- This sample assumes a ñ5 Volt range on all DACs."); puts("-- All remaining jumper settings are irrelevant."); Address = AskForBaseAddress(0x350); //Prompt for base address clrscr(); printf("\n\nBase Address = %3X", Address); puts("\n\n\n\n\r"); puts("Should I perform a hardware-reset clear?"); puts("Answer Y if the card was just powered-up,"); puts("or N if you've already done this since the last reset."); do { key = toupper(getch()); } while ((key != 'Y') && (key != 'N')); puts(""); if (key == 'Y') { for (Channel = 0; Channel < 16; Channel++) OutputValue(Channel, 0x8000); /* Note: 0x0000 if Unipolar Mode (per channel) Be aware that the OutputValue routine does not necessarily update the outputs. In this particular case, it does not. The card powers up in simultaneous Update mode, therefore, the output command is not reflected in the voltages until an update command is issued -- the next line: */ inportb(Address + 10); /* This updates the outputs, and exits simultaneous mode. We could have remained in simultaneous mode and still updated the outputs by using Address + 8 instead of +10. */ puts("All of the outputs have been updated with Bipolar zero (0x8000)"); puts("Assuming power-on condition, nothing should have changed."); puts("(Incidentally, any channels that are in the Unipolar range"); puts("should have simultaneously changed to +2«V outputs.)"); } puts("\nPress any key to output 2«V on all channels, non-simultaneously"); getch(); inportb(Address + 2); // remove from simultaneous, offset // 10 would also work. for (Channel = 0; Channel < 16; Channel++) OutputValue(Channel,0xC000); // these each take effect immediately. inportb(Address + 0); // place in simultaneous mode for (Channel = 0; Channel < 16; Channel++) OutputValue(Channel,0xFFFF); // these don't do a thing to // the outputs yet. puts("\nAll channels have been written to with 0xFFFF, but the outputs don't"); puts("change. Press any key to initiate simultaneous update of all channels."); puts("Outputs will all change at the same time to 4.9998V DC."); getch(); inportb(Address + 8); // still in simultaneous mode, updated outputs. puts("All channels should have changed to full-scale.\n"); getch(); // note that we don't issue a Simultaneous Update Mode read command -- we're // still in simultaneous mode from above. for (Channel = 1; Channel <= 7; Channel += 2) OutputValue(Channel, 0x0000); // these don't do a thing to // the outputs yet. puts("\nChannels 1, 3, 5, and 7 have been written to with 0x0000, but"); puts("the outputs haven't changed."); puts("Press any key to change channels 1 through 7 odd to -5V, simultaneously."); getch(); inportb(Address + 10); // update and remove from simultaneous mode. puts("The channels should have changed now."); puts("\nPress any key to continue with program."); do { clrscr(); printf("Base Address = %3X", Address); puts("\n\n\n\n\r"); puts("Borland C Language Sample for D/A16-16. Version 1.05\r\n\n"); puts("The program will now allow you to type in any count value desired"); puts("for output on any channel desired.\n"); puts("Enter ChannelNumber Space HexCounts Ex: 15 A000 [enter]\n"); gotoxy(2, 15); cputs("> "); // just clear out the last value. do { if (Channel >= 16) puts("Channel must be less than 16."); gotoxy(4, 15); scanf("%i %x", &Channel, &Value); } while (Channel >= 16); OutputValue(Channel, Value); // this happens immediately, not // in simultaneous mode puts("Press [ENTER] to Exit Program, or any other key to continue."); } while(getch() != 13); // Program Complete. Outputs remain the same. }