/**************************************************************************** * C SAMPLE #4: SAMPLE4.C * * * * This sample will continuously read the digital input port and display * * the value bit by bit. * * * ****************************************************************************/ #include #include #include #include #include "kbinp.h" #define uint unsigned int void DisplayInfo( void); uint AskForBaseAddress( uint); void IOPermission(unsigned abase) { if(ioperm(abase,8,1)<0) { fprintf(stderr, "NO IO PERMISSION\n"); } } int main() { unsigned int i, BaseAddress = 0x340; system("clear"); DisplayInfo(); // tell the user what to expects BaseAddress = AskForBaseAddress(BaseAddress); IOPermission(BaseAddress); outb(0, BaseAddress + 1); // tristate the digital port and set to zero outb(0x20, BaseAddress); // initialize the control register do // loop until the user press enter { system("tput cup 12 0"); for( i = 0; i <= 7; i++) { if( inb( BaseAddress+1) & ( 0x80 >> i)) putchar('1'); else putchar('0'); } putchar('\n'); system("sleep 1"); }while(kbhit()==0); system("sleep 1"); outb(0, BaseAddress + 1); // tristate the digital port return 0; } void DisplayInfo() { printf(" C SAMPLE #4: SAMPLE4.C\n" "\nThis sample will continuously read the digital input port and " "display the\n" "value bit by bit.\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 */