#include #include #include #include #include #include #include #include "adcard.h" 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 */ void main(void) { unsigned int BASE=0x340; unsigned int data, chan; unsigned int timeout = 65535; clrscr(); puts("Sample 9\n"); puts("This program will read data from all channels on the A/D card,"); puts("using the Card Driver Module."); BASE=AskForBaseAddress(BASE); puts(""); gotoxy(1,19); puts("Press any key to exit."); outp(BASE+2,0); outp(BASE+0,4); while (!kbhit()) { delay(250); gotoxy(1,10); for (chan = 0; chan < 8; chan++) { timeout = 65535; SETCHANNEL(BASE, chan << 4); // set channel delay(1); STARTCONVERSION(BASE); // start conversion while (CHECKFOREOC(BASE) && (timeout > 0)) timeout--; if (timeout == 0) printf("A/D timeout"); else clreol(); data = RETRIEVEANALOGCONVERSION(BASE); printf("Chan %hu Data Read: %4hu\n", chan, (unsigned)data); } } gotoxy(1,20); }