/* ****************************************************************** This command configures a port as an input or output. The Direction field can be either DIGITALIN or DIGITALOUT depending on whether the port is to be configured as an input or output. Valid ports are PORTA, PORTB, PORTCL and PORTCH. Direction bit can be either DIGITALIN or DIGITALOUT. ********************************************************************** */ int DConfigPort(int Port, int Direction) { int mask, OldByte, NewByte; OldByte = inb(DCONFIGPORT); /*read the current value in register*/ switch (Direction) { case DIGITALIN: /* determine mask for DIGITALIN */ if (Port == PORTA) mask = 0x10; else if (Port == PORTB) mask = 0x02; else if (Port == PORTCL) mask = 0x01; else if (Port == PORTCH) { mask = 0x08; Port = 0x30e; } else return(2); /* error - not valid port */ NewByte = OldByte | mask; /* new data for register */ break; case DIGITALOUT: /* determine mask for DIGITALOUT */ if (Port == PORTA) mask = 0xef; else if (Port == PORTB) mask = 0xfd; else if (Port == PORTCL) mask = 0xfe; else if (Port == PORTCH) { mask = 0xf7; Port = 0x30e; } else return(2); /* error - not a valid port */ NewByte = OldByte & mask; /* new value for register */ break; default: return(1); /* error - not a valid direction */ break; } printf("The value of NewByte is --> %x.\n", NewByte); outb(NewByte, DCONFIGPORT); /* write config data to register */ return(0); /* no errors detected */ }