did you simply try to add ...
The important part is to set the PORT (or LAT) registers BEFORE setting the TRIS registers to outputs.
Otherwise the pins will be in output mode for a period of time but the outputs aren't specified.