Ports
The PINs on a microcontroller are grouped logically together into ports, to a maximum of 8 PINS for an 8-BIT microcontroller. The ports are tied directly to registers internal to the device. The registers determine the operation of the port which includes the direction, the port operation, and which peripherals are linked to and work with the port.
When the device is reset or restarted, the PICs ports are reset to their default values.
The TRIS or tri-state register is configured to determine whether the PIN works as an input or an output. Pins can be configured individually, alternatively, the entire register can be written to at one time, configuring the pins simultaneously.
Certain device families use the GPIO register to configure the PORTS.
The TRIS registers are named alphabetically, starting with TRISA, and depending on the device pin count will have more registers in relation to the number of pins. Owing to the manner in which the device architecture is implemented, you may encounter incomplete ports that do have a full register of PINs. Always check the datasheet for all devices to ensure that you have complete information with regard to a device.
When configuring the TRIS register there are two options:
- Set bits individually
- Write to the register as a single value
Shown below is an example of how to write to an individual bit in the TRIS register.
Shown below is an example of how to write a single value to the TRIS register.
In the first example, which is a single write, the value is setting individual bits. In the second, a hex value is written.
๏ปฟ