Close
0%
0%

AVR8 GPIO: Configuring AVR GPIO pins in C, nicely

This is a relatively humble header file which makes it easy to define a single name for GPIO pins, without losing any performance.

Similar projects worth following
  • Description
  • Details
  • Files 0
  • Components 0
  • Logs 0
  • Instructions 0
  • Discussion 0
Accessing GPIO pins in C on AVR8 involves setting up three different registers: DDRx, PORTx and PINx, each GPIO pin has a bit in each of these registers for setting direction, writing the state and reading the state, this means that if you want to define a constant for a port then you'd need up to four constants, which is not very D.R.Y., this is a particular problem when you want to define the GPIO ports one place to ease porting.

The avr8gpio.h header allows rolling two bits of information into one constant: The port and the pin, so you can finally define a GPIO pin with a single constant, like so:

#include "avr8gpio.h"

#define LED GPB0

void init() {
GPOUTPUT(LED);
}

void setLed(uint8_t on) {
GPWRITE(LED, on);
}

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates