/*-------------------------------------------------------------------- * C LANGUAGE SAMPLE 4 : SAMPLE4.C * * Sample program for ACCES AD12-8 A/D Converter/Counter-Timer * demonstrating register level data aquistion from the AD12-8. * * Last Modification : 2/4/98 *------------------------------------------------------------------*/ #include #include #include #include #include unsigned base; 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 intro(void) { clrscr(); puts("Sample 4 AD12-8 ACCES I/O Products Inc."); puts("\n"); puts("This sample reads the eight analog inputs from the AD12-8 and "); puts("displays them for you."); puts("\n"); puts("Board Configuration Requirements:"); puts("\n"); puts("RANGE: 5 Volt Range"); puts("POLARITY: Bipolar"); puts("\n"); puts("\n"); puts("\n"); puts("Please press any key to set base address."); getch(); clrscr(); base = AskForBaseAddress(0x300); clrscr(); printf("Address entered was %X hexidecimal.\n", base); printf("Is this the correct address for your configuration? (Y/n)"); while(!kbhit()); if (toupper(getch()) == 'N') { printf("\n\nPlease restart program and enter correct address.\n"); exit(1); } } /* end of Intro */ void main(void) { unsigned char channel; int counts; float volts; int i,j; char c = '?'; intro(); while (c != 'E') { clrscr(); printf(" Channel Counts Volts\n"); printf(" ------- ------ -----\n"); for (channel = 0; channel <= 7; channel++) { outportb(base+2, channel); /* Set channel */ for (i = 0; i < 1000; i++) /* Wait for settle count */ ; outportb(base+1,0); /* Start A/D conversion */ j = 0; /* Wait for EOC or timeout */ while (((inportb(base+2) & 0x80) >= 0x80) || (j < 1000)) j++; counts = inport(base) >> 4; /* Read count data */ /* Scaling 5v range on 12 bit device = 0.00244v/count */ volts = ((float)counts-2048.0)*0.00244; /* Display results */ printf("%14d%12d%12.3f\n",channel,counts,volts); } printf("\n Press 'E' to exit program\n"); printf(" Press any other key to update readings"); while (!kbhit()) ; c = toupper(getch()); } /* end of while not 'E' */ } /* end of main */