Content originally posted in LPCWare by NXP_Paul on Mon Sep 30 12:33:31 MST 2013
The problem with the first solution is that it does not leave reserved bit 6 set to 1. Also, the mode bits [4:3] are 01, so you should use 0xC9 rather than 0x51:
LPC_IOCON->R_PIO1_0 = 0xC9;
I do not see a problem using this method to configure the IOCON register, as long as the value is calculated correctly.
The second method is okay, but again, don't clear the reserved bit 6. The ANDing shouldn't be necessary.
LPC_IOCON_R_PIO1_0 &= ~(0xbf);
LPC_IOCON_R_PIO1_0 |= 0x89 & 0xff;
Since your example only requires changing the FUNC bits [2:0], it would probably be best to only change these 3 bits, minimizing the chance of an error:
LPC_IOCON_R_PIO1_0 &= ~0x07;
LPC_IOCON_R_PIO1_0 |= 0x01;
The third method is okay but you don't need to shift the value by 8 bits.
Most of the NXP example code uses the second method.