#include #include #include #include #include #include #include unsigned AskForBaseAddress(unsigned int OldOne) { char msg[7]; int NewOne = 0, Success = 0, Dummy; int AddrInputPosX, AddrInputPosY; puts("Please 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 */ #define CHECKFORBUSY(BASE) (!(inportb(BASE+0) & 0x80)) void main(void) { unsigned int BASE=0x300; unsigned int data, chan; unsigned int timeout = 65535; clrscr(); puts("Sample 0\n"); puts("This program will read data from all channels on the A/D card.\n"); BASE=AskForBaseAddress(BASE); outportb(BASE + 0x18, 0x01); gotoxy(1,19); puts("Press any key to exit."); while (!kbhit()) { delay(250); gotoxy(1,10); for (chan = 0; chan < 8; chan++) { timeout = 65535; outportb(BASE+2, chan); // write channel while (CHECKFORBUSY(BASE) && (timeout > 0)) timeout--; if (timeout == 0) printf("A/D timeout"); else clreol(); data = inport(BASE+2); printf("Chan %hu Data Read: %04x\n", chan, (unsigned)(data)); } } gotoxy(1,20); }