The output state of the pin is stored, even when it is an input. When you make it an input, it automatically goes wherever the input is pulling it. As soon as you make it an output, the old output value is restored.
The way to ensure it goes to the desired state is to set the value prior to TRISing it to an output.
Bookmarks