First thing you set out to do when you get your hands on a new microcontroller is right the HelloWorld of our world, the blinky code. In the blinky project, an LED connected to microcontrollers GPIO pins. GPIO or General Purpose Input Output pins are used as an input or output pins. In the blinky project case, we use it as output.
Configuring GPIO pin as an output
Now if you have worked with Arduino it’s quite simple. You simply use the pinMode() command to set any pin to OUTPUT or INPUT. But as you start working with more advanced controllers and have a deeper access to the controller there are few other things that have to be configured to be able to use a pin as INPUT or OUTPUT.
Setting up GPIO pins for PIC microcontrollers
There are three registers that you need to familiarize yourself when working with PIC microcontrollers specifically, others may be the same or different.
TRIS means TriState or three different settings. Now, this particular register corresponding to a GPIO pin is used to select whether the pin is being used as an input or an output. But you may ask what’s the third state as the name suggest? It’s a high impedance state. This is the input state where due to high impedance no current flows into the microcontroller. The other two states are 0 and 1 for the output pin.
Tristate is listed as a trade mark thus microchip uses TRIS as shortform meaning the same thing.https://trademarks.justia.com/876/18/tristate-87618512.html
The LAT register corresponding to a GPIO pin is used to read the value on the pin. Remember to use a GPIO as INPUT corresponding TRISx register should be set accordingly.