/******************************************** sample0.c for ad12-8 must be in su mode for ioperm to work *********************************************/ #include #include #include #include void intro(void){ puts("\n\nSample 0"); puts("This sample reads the eight analog inputs and "); puts("displays them for you."); puts("Board Configuration Requirements:"); puts("RANGE: 5 Volt Range"); puts("POLARITY: Bipolar\n"); }//intro unsigned int AskForBaseAddress(unsigned int OldOne){ char msg[3]; unsigned int NewOne = 0; int index = 0; int letter; puts("Please enter Base Address of Data Card"); puts("Input should be 3 HEX numbers"); puts("Then press ENTER"); while((letter = getchar())!='\n') msg[index++] = letter; sscanf(msg, "%X", &NewOne); return((NewOne>=0x100)&&(NewOne<=0x3f0)) ? NewOne : OldOne; }//Ask void IOPermission(unsigned abase){ if(ioperm(abase,8,1)<0) { fprintf(stderr, "NO IO PERMISSION\n"); exit(EXIT_FAILURE); }//if }//IOPermission int main(void) { unsigned base; unsigned char channel; int counts; float volts; int j; char c = '?'; intro(); base = AskForBaseAddress(0X350); printf("Address entered was %X hexadecimal,\n", base); puts("is this the correct address for your configuration? (Y/N)"); if(toupper(getchar())=='N') { puts("\n\nPlease restart Program and enter correct address.\n\n"); exit(1); }//if IOPermission(base); while(c != 'E') { puts(" CHANNEL COUNTS VOLTS"); puts(" ------- ------ -----"); for(channel = 0; channel <= 7; channel++) { outb(0X00+channel,base+2);//channel for analog input for(j = 0; j < 10000; j++) ; outb(0X00,base+1);//start A/D conversion j = 0; while(((inb(base+2)&0X80)>=0X80)&&(j<100)) j++; counts = inw(base) >> 4; volts = ((float)counts-2048.0)*0.00244; printf("%14d%12d%12.3f \n",channel,counts,volts); }//for puts("Press e then ENTER to exit program, "); puts("Press any other key then ENTER to cotinue."); do{ c = toupper(getchar()); }while(getchar() != '\n'); }//while return 0; }//main