/*-------------------------------------------------------------------- * C LANGUAGE SAMPLE 0 * * Sample program for the Analog and Digital I/O card * demonstrating register level data aquistion. * * Last Modification : 17 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 eight analog inputs and "); puts("displays them for you."); puts("\n"); 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 Range\n"); printf(" ------- ------ ----- -----\n"); for (channel = 0; channel <= 7; channel++) { outportb(base+2, channel); // Set channel if ((channel % 2) == 0) // Set gain: outportb(base+3, 0x00); // +/-5v range on even chans else // +/-10v range on odd chans outportb(base+3, 0x08); 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 = (counts-2048)*0.00244; // Display results printf("%14d%12d%12.3f",channel,counts,volts); if ((channel % 2) == 0) printf(" +/-5v\n"); else printf(" +/-10v\n"); } printf("\n Press 'E' to exit program\n"); while (!kbhit()) ; c = toupper(getch()); } /* end of while not 'E' */ } // end of main