GPIOs are micro-controller signals whose state can be controlled through software. GPIOs can be used for controlling LEDs, checking key state, controlling LCD displays, etc.
The GPIO module provides APIs to control GPIO signals. The GPIO
functions are declared in gpio.h
. The pins are indicated using
microcontroller specific macros. The macros for each microcontroller
is listed in the following table.
Microcontroller | Port | Macros |
---|---|---|
P89V664 | Port 0 |
GPIO0_0 - GPIO0_7
|
- | Port 1 |
GPIO1_0 - GPIO1_7
|
- | Port 2 |
GPIO2_0 - GPIO2_7
|
- | Port 3 |
GPI03_0 - GPIO3_7
|
- | Port 4 |
GPIO4_0 - GPIO4_3
|
P89V51RD2 | Port 0 |
GPIO0_0 - GPIO0_7
|
- | Port 1 |
GPIO1_0 - GPIO1_7
|
- | Port 2 |
GPIO2_0 - GPIO2_7
|
- | Port 3 |
GPI03_0 - GPIO3_7
|
LPC1343 | Port 0 |
GPIO0_0 - GPIO0_11
|
- | Port 1 |
GPIO1_0 - GPIO1_11
|
- | Port 2 |
GPIO2_0 - GPIO2_11
|
- | Port 3 |
GPI03_0 - GPIO3_3
|
The following example program blinks the LED, with a period of 1 second.
Listing 14.1. LED Blink
#include <board.h>
#include <delay.h>
#include <gpio.h>
int main()
{
board_init();
delay_init();
gpio_init();
gpio_enable_pin(LED1_GPIO);
gpio_direction_output(LED1_GPIO, 0);
while (1) {
gpio_set_pin(LED1_GPIO, 0);
mdelay(500);
gpio_set_pin(LED1_GPIO, 1);
mdelay(500);
}
return 0;
}