Digital Outputs
The TRISx register controls the direction of data on each bit of a port. Each pin in a port is mapped to a bit in a TRIS register. The data direction for each pin can be set by writing an 8-bit value to the TRIS register individually by setting/clearing a TRIS register bit or the direction of all the bits in a port.
At RESET all the bits associated with pins in the TRIS registers are set to '1' making all pins High-Z inputs.
Making a pin a Digital Output Pin
To configure a pin as a digital output, '0's need to placed in corresponding TRISxregister bits.
Writing to a Digital Pin
The output value for each port can be loaded by writing to the port's LAT register. (Just as all the other port control registers the LATx registers names are lettered. (LATxregisters start with LATA, and proceed through LATB, LATC…)
Writing a '1' to a bit in the LAT register will drive the pin to Vdd. A '0' in a LAT bit will pull the pin to Vss.
Writing to the PORTx register will also drive the output signal just as writing to the LATx register.
However, under high loads or at high frequency, if multiple bit modification commands ( BSF, BCF) are written sequentially to an output PORT register, it is possible the last bit-manipulation instruction will overwrite a previous instruction resulting in an incorrect value on the output port. To avoid the possibility of this occurring it is highly recommended that output always is made to the LATx register.
Example code:
The code shown here is an example of configuring all the pins in PORTB as digital outputs. Once configured as output pins, the lower 4 bits of the port are driven high while the upper 4 bits are set to '0'.

Question: Why was the LAT register cleared before the TRIS register was set?
Answer: At RESET the contents of the LATx registers are unknown. It is recommended the value of all output LAT register bits be set to a known (and safe) value before the output pins are enabled. This will prevent any spurious, unintended output pulses.
In this example, only the configuration of RB3 is changed to a digital output. Once configured, RB3 is driven high. All other pins (and their respective control register bits) are left unchanged.
