// A simple program to read switches and write to the LEDs /* Configure TRISD so that pins RD[7:0] are outputs and RD[11:8] are inputs. Read the switches by examining pins RD[11:8] Write this value back to RD[3:0] to turn on the appropriate LEDs. c code */ #include void main(void) { int switches; // set RD[7:0] to output, RD[11:8] to input TRISD = 0xFF00; while (1) { switches = (PORTD >> 8) & 0xF; // Read and mask RD[7:4] PORTD = switches; // display on the LEDs } }