The general purpose of I/O pins can be considered the simplest of peripherals. They allow the Microcontroller (MCU) to monitor and control other devices. To add flexibility and functionality to a device, some pins are multiplexed with alternate function(s). These functions depend on which peripheral features are on the device. In general, when a peripheral is functioning, that pin may not be used as a general-purpose I/O pin. Most of the MCU support the Peripheral Pin Select (PPS) feature. The PPS constitutes pins that users can map to the input and/or output of some digital peripherals.
Based on the make the handling of the GPIO port varies as they all have different registers names and operations. However, some of the common factors can be noticed.
To make a
Bit-level sets and clear registers allow a single instruction set or clear of any number of bits in one port
All I/O default to inputs after reset
Direction control of individual bits is possible
Output can be made high or 1 by setting the I/O and low or 0 by clearing the I/O.
Source: PIC Microcontroller
Pins can also be configured as digital inputs or outputs, and analogue inputs or outputs. When
configured as digital inputs, they are either TTL buffers or Schmitt Triggers. When configured as digital outputs, they are either CMOS drivers or open-drain outputs. Many pins also support one or more peripheral modules. When configured to operate with a
peripheral, a pin may not be used for general input or output. In many cases, a pin must still be configured for input or output, although some of the other peripherals override this configuration. The priority of the peripheral function depends on the order of the pin description in the pin diagram of the specific product data sheet.
Refer to the specific device datasheet for a description of the available I/O ports, peripheral
multiplexing details and available peripheral pin select pins.
Application of General purpose I/O
Driving LEDs, or other indicators
Controlling off-chip devices
Sensing digital inputs, detecting edges
Bringing the part out of Power Down mode