Strange port behavior (PIC24F)
Writing to an element of a bitfield will generally cause a read-modify-write operation to be performed. In particular, the line

PORTBbits.RB4 = 1;


will have the same behavior as

PORTB = PORTB | (1&lt;&lt;4);


My PIC is a bit rusty, but I believe that reading PORTB will return the current state of the pins, rather than the value last written?