#include #include #include #include #include unsigned int BASE= 0x300; /*************************************************************************** * FUNCTION: AskForBaseAddress * * PURPOSE: Prompt user to enter base address for their I/O card. * **************************************************************************/ unsigned AskForBaseAddress(unsigned int OldOne) { char msg[7]; int NewOne = 0, Success = 0, Dummy; int AddrInputPosX, AddrInputPosY; puts("\nPlease enter the Base Address OF THE DAC 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() { char key_entered; double val=0.0; unsigned counts=0; BASE=AskForBaseAddress(BASE); do { printf("Base Address %04x, DACs at +C and +E\n",BASE); printf("Press `1234567890 to output %% to the DACs\n"); puts("`= zero percent, 1=10%, 9=90%, 0=100%, etc."); puts("Press N to exit"); key_entered = getch(); clrscr(); if (key_entered=='`') { val=0.0; } else if (key_entered == '0') { val=1.0; } else if (isdigit(key_entered)) { val=0.1*(key_entered-'0'); } else continue; counts=(4095.0*val); outport(BASE+0x0C,counts); outport(BASE+0x0E,4095-counts); printf("Wrote %04x to Base+C, and %04x to Base+E\n",counts,4095-counts); } while (key_entered != 27); }