#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+2) & 0x80) void main(void) { unsigned int BASE=0x340; int data,chan=0; unsigned long int timeout = 655354L; clrscr(); puts("Sample 6\n"); puts("This program will read data from channel 0 on the A/D card\n" "at the rate input to pin 25 (active low edge to start).\n" "Therefore, to use this sample, a signal must be provided to this\n" "pin. It is possible to use the output of the counter, or any\n" "frequency generator."); BASE=AskForBaseAddress(BASE); outportb(BASE+2,0); outportb(BASE+0,0xF4); while(!kbhit()){ timeout=655354L; while(!CHECKFORBUSY(BASE) && (--timeout));//wait for start of conversion while(CHECKFORBUSY(BASE) && (timeout--)); //wait for end of conversion data=(inport(BASE+6)>>4) & 0x0FFF; //read data from conversion gotoxy(10,12+chan); printf("Channel: %i Data Read:%4x",chan,data); if (timeout==0) puts(" A/D Timeout Error");else clreol(); chan++; chan%=8; outportb(BASE+2,chan);//setup next channel } gotoxy(1,20); }