/**************************************************************************** * C SAMPLE #4: SAMPLE4.C * * * * This sample will continuously read the digital input port and display * * the value bit by bit. * * * ****************************************************************************/ #include #include #define uint unsigned int void DisplayInfo( void); uint AskForBaseAddress( uint); void main() { unsigned int i, BaseAddress = 0x340; clrscr(); DisplayInfo(); // tell the user what to expects gotoxy( 1, 5); // set the screen position for AskForBaseAddress() BaseAddress = AskForBaseAddress( BaseAddress); outp( BaseAddress + 1, 0); // tristate the digital port and set to zero outp( BaseAddress, 0x20); // initialize the control register while( !kbhit()) // loop until the user presses a key { gotoxy( 30, 12); for( i = 0; i <= 7; i++) { if( inp( BaseAddress+1) & ( 0x80 >> i)) printf( " 1"); else printf( " 0"); } } puts( "\n"); // add some space after our output line if( kbhit()) if( !getch()) getch(); // clean up the key buffer outp( BaseAddress + 1, 0); // tristate the digital port } void DisplayInfo() { puts( " C SAMPLE #4: SAMPLE4.C"); printf( "\nThis sample will continuously read the digital input port and" " display the\n"); puts( "value bit by bit."); } unsigned AskForBaseAddress( unsigned int OldOne) { char msg[7]; int NewOne = 0, Success = 0, Dummy; int AddrInputPosX, AddrInputPosY; puts("\nPlease enter the Base Address for your card (in hex)"); printf("or press ENTER for %X.\n>", OldOne); AddrInputPosX = wherex(); AddrInputPosY = wherey(); do { gotoxy(AddrInputPosX, AddrInputPosY); clreol(); msg[0] = 5; msg[1] = 0; cgets(msg); sscanf(msg + 2, "%x", &NewOne); Success = 1; Dummy = NewOne; if (msg[1] == 0) { gotoxy(AddrInputPosX, AddrInputPosY); printf("%X", OldOne); Success = 1; Dummy = OldOne; } } while(!Success); return (Dummy); } /* end of AskForBaseAddress */