#include #include #include #include #include #include #include "kbinp.h" unsigned AskForBaseAddress(unsigned int OldOne) { char msg[3]; unsigned int newone; unsigned int temp = 0; int index = 0; int letter; puts("Please enter the Base Address for your card (in hex)"); printf("or press ENTER for %X.\n>", OldOne); while(temp==0) { newone=0; index=0; while((letter = getchar())!='\n') //Read char by char and store in Msg msg[index++] = letter; sscanf(msg, "%X", &newone); if(newone==0){ //Check to see if address was inputed temp=OldOne; //Assign default if not } else if((newone>=0x100)&&(newone<=0x3f0)){ //Check to see if inputed addres is valid temp=newone; } else { //If Newone invalid ask for new value. printf("\nEnter the Base Address or press ENTER for %x > ", OldOne); for(index=0; index<=3; index++) msg[index]=0; } //Run while until temp = valid address } return(temp); } /* end of AskForBaseAddress */ #define CHECKFORBUSY(BASE) (!(inb(BASE+2) & 0x80)) void IOPermission(unsigned abase) { if(ioperm(abase,8,1)<0) { fprintf(stderr, "NO IO PERMISSION\n"); } } int main(void) { unsigned int data; unsigned chan, BASE; unsigned int timeout = 65535; puts("Sample 0\n"); puts("This program will read data from all channels on the A/D card.\n"); BASE=AskForBaseAddress(0x340); puts(""); IOPermission(BASE); //Checks for I/O Read/Write permissions outb(0x00, BASE+2); outb(0x00+4, BASE+0); system("clear"); system("styy -echo"); //Disable echo of stdin to stdout do { system("tput cup 1 0"); //Setting cursor position for (chan = 0; chan < 8; chan++) { timeout = 65535; outb(0x00+chan, BASE+2); // write channel outb(0x00, BASE+3); // start conversion while(!CHECKFORBUSY(BASE) && (timeout > 0)) timeout--; if (timeout == 0) puts("A/D timeout"); data = inb(BASE+6); printf("Chan %hu Data Read: %4hu\n", chan, (unsigned)(data >> 4)); } puts("Press ENTER to exit."); }while(kbhit()==0); //Wait for keypress system("stty echo"); //Enable echo of stdin to stdout return 0; }