#include #include #include #include #include #include "kbinp.h" void IOPermission(unsigned abase) { if(ioperm(abase,8,1)<0) { fprintf(stderr, "NO IO PERMISSION\n"); } } unsigned AskForBaseAddress(unsigned int OldOne) { char msg[3]; unsigned int newone; unsigned int temp = 0; int index = 0; int letter; puts("\nPlease 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') msg[index++] = letter; sscanf(msg, "%X", &newone); if(newone==0){ temp=OldOne; } else if((newone>=0x100)&&(newone<=0x3f0)){ temp=newone; } else { printf("\nEnter the Base Address or press ENTER for %x\n", OldOne); for(index=0; index<=3; index++) msg[index]=0; } } return(temp); } /* end of AskForBaseAddress */ #define CHECKFORBUSY(BASE) (inb(BASE+2) & 0x80) int main(void) { unsigned int BASE=0x340; int data,chan=0; unsigned long int timeout = 655354L; system("clear"); puts("Sample 6\n"); puts("This program will read data from channel 0 on the A/D card\n" "at the rate input to pin 25 (active low edge to start).\n" "Therefore, to use this sample, a signal must be provided to this\n" "pin. It is possible to use the output of the counter, or any\n" "frequency generator.\n"); IOPermission(BASE); BASE=AskForBaseAddress(BASE); outb(0,BASE+2); outb(0xF4,BASE+0); while(kbhit()==0){ timeout=655354L; while(!CHECKFORBUSY(BASE) && (--timeout));//wait for start of conversion while(CHECKFORBUSY(BASE) && (timeout--)); //wait for end of conversion data=(inb(BASE+6)>>4) & 0x0FFF; //read data from conversion system("tput cup 12 0"); printf("Channel: %i Data Read:%4x\n",chan,data); if (timeout==0) puts(" A/D Timeout Error\n"); chan++; chan%=8; outb(chan,BASE+2);//setup next channel } return 0; }