Programming binary values [0000 to 1111] to port pins in C?
I'll leave this as pseudo-code as I don't know the compiler your're using but one approach is something like the following. It does a bitwise AND on each bit of the value and shifts it into the least significant bit, some compilers won't require that but there's no harm including it if unsure.

void set_output_v(uint8_t v)
{
    P2.0 = v &amp; 0x01;
    P2.1 = (v &amp; 0x02) &gt;&gt; 1;
    P2.2 = (v &amp; 0x04) &gt;&gt; 2;
    P2.3 = (v &amp; 0x08) &gt;&gt; 3;
}


On many compilers there will also be a way to set a whole port at a time. Try the above code first but you may also be able to do something like the following to keep the high nybble of P2 and shift the value v into the lower nybble.

P2 = (P2 &amp; 0xF0) | v;