Step 1: GPIO and Software-Based Delays

Last modified by Microchip on 2026/06/26 07:37

Understanding General-Purpose Input/Output (GPIO) 

GPIO stands for General-Purpose Input/Output.

Microcontroller pins configured as GPIO can be set as either input (to read signals) or output (to send signals).

When a pin is set as output, you can drive it HIGH (logic 1) or LOW (logic 0).

Driving the pin HIGH or LOW can turn external devices (like LEDs) ON or OFF.

The output value written to a pin is stored in a Latch (LAT) register, which holds the last driven value on the pin until it is changed by the program.

When a pin is configured as input, a pull-up resistor can be enabled to pull the pin to a default HIGH state when no external signal is applied, preventing it from floating.

Similarly, a pull-down resistor pulls the pin to a default LOW state when no external signal is applied, ensuring a stable and defined logic level.

Example:

a) Setting the pin HIGH turns the LED ON (if connected in active-high configuration).

b) Setting the pin LOW turns the LED OFF.

c) The LAT register retains the HIGH or LOW value until the program writes a new value to it.

d) If no signal is connected to an input pin, enabling a pull-up or pull-down resistor prevents undefined or floating behavior.


Understanding Software-Based Delays

A software delay is a method to pause program execution for a set period using code (usually loops).

It does not use hardware timers; instead, it relies on the processor executing instructions that do nothing No Operations (NOPs).

The processor repeatedly executes a loop, consuming time.

The length of the delay depends on the number of loop iterations and the processor speed.