before you go to too much trouble try what henrik suggests

clear all output ports before setting the tris registers and lose that delay in between