/*-------------------------------------------------------------------- * C LANGUAGE SAMPLE 0 * * Sample program for the Analog and Digital I/O card * demonstrating register level data aquistion. * * Last Modification : 18 November 1994. *------------------------------------------------------------------*/ #include #include #include #include #include unsigned base; unsigned AskForBaseAddress(unsigned int OldOne) { char msg[81]; unsigned int NewOne=0; window(5,5,75,19); textcolor(WHITE); textbackground(BLUE); clrscr(); window(10,7,70,17); cprintf("\n\n\nPlease enter the Base Address for your card (in hex)\n\r" "or press ENTER for %X.\n\r" ">",OldOne); msg[0]=5; cgets(msg); sscanf(msg+2,"%x",&NewOne); textcolor(LIGHTGRAY); textbackground(BLACK); window(1,1,80,24); clrscr(); return ((NewOne>=0x100)&&(NewOne<=0x3f0)) ? NewOne : OldOne; } /* end of AskForBaseAddress */ void intro(void) { clrscr(); puts("Sample 0"); puts("\n"); puts("This sample reads the sixteen analog inputs and "); puts("displays them for you."); puts("\n"); puts("\n"); puts("Board Configuration Requirements:"); puts("\n"); puts("CHANNEL SELECTION: 16 Channel Single-Ended"); 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, i; float volts; char c = '?'; intro(); /* Init AD816 to Bip, +/-5v range */ outportb(base+2, 0x30); while (c != 'E') { clrscr(); printf(" Channel Counts Volts\n"); printf(" ------- ------ -----\n"); for (channel = 0; channel <= 15; channel++) { /* Set Channel */ outportb(base+2, (inportb(base+2) & 0xF0) + channel); /* Reset EOC interrupt */ outportb(base+1, 0); /* Start A/D conversion */ outportb(base, 0); /* Wait for EOC or timeout */ i = 0; while ( ((inportb(base+2) & 0x80) < 0x80) && (i <= 1000) ) i++; /* if timeout display error and exit program */ if (i > 1000) { fprintf(stderr,"\n\nError: Timeout on channel\n\n", channel); exit(1); } /* Get count data */ counts = inportb(base); /* Scaling 5v range on 8 bit device = 0.039 volts/count */ volts = (counts - 128) * 0.039; /* Show data */ printf("%14d%12d%12.3f\n",channel,counts,volts); } /* end of for channel */ printf("\n Press 'E' to exit program\n"); while (!kbhit()) ; c = toupper(getch()); } /* end of while not 'E' */ } /* end of main */