For a pin to be a digital I/O, the analog capabilities of the pin must be disabled if the pin presents this feature. Do this by configuring the corresponding ANSEL register. The TRIS registers must be configured and then, using the LAT registers, set the output values of the pins.
Setting a TRISx bit (= 1) will make the corresponding PORTx pin an input. Clearing a TRISx bit (= 0) will make the corresponding PORTx pin an output. Although, in some cases, the same pin is used both as output and input of the module. For example, for all modes of EUSART operation, the TRIS control bits corresponding to the RX/DT and TX/CK pins should be set to 1.
The EUSART control will automatically reconfigure the pin from input to output as needed. Another example is the SDA line of the I²C module, which is also an input and an output. The corresponding TRIS bit should be set as 1 and the module will take control of the pin. For more information see the PORTx I/O Summary table for each device.