text: /***********************************************************************
   * 
   * Alternately toggle two LEDs when a push button is pressed. Use 
   * functions from GPIO library.
   * ATmega328P (Arduino Uno), 16 MHz, AVR 8-bit Toolchain 3.6.2
   *
   * Copyright (c) 2019-2020 Tomas Fryza
   * Dept. of Radio Electronics, Brno University of Technology, Czechia
   * This work is licensed under the terms of the MIT license.
   * 
   **********************************************************************/
  
  /* Defines -----------------------------------------------------------*/
  #define LED_GREEN   PB5     // AVR pin where green LED is connected
  #define LED_RED		PC0
  #define BTN			PD0
  #define BLINK_DELAY 500
  #ifndef F_CPU
  #define F_CPU 16000000      // CPU frequency in Hz required for delay
  #endif
  
  /* Includes ----------------------------------------------------------*/
  #include <util/delay.h>     // Functions for busy-wait delay loops
  #include <avr/io.h>         // AVR device-specific IO definitions
  #include "gpio.h"           // GPIO library for AVR-GCC
  
  /* Function definitions ----------------------------------------------*/
  /**
   * Main function where the program execution begins. Toggle two LEDs 
   * when a push button is pressed. Functions from user-defined GPIO
   * library is used instead of low-level logic operations.
   */
  int main(void)
  {
      /* GREEN LED */
      GPIO_config_output(&DDRB, LED_GREEN);
      GPIO_write_low(&PORTB, LED_GREEN);
      /* second LED */
      GPIO_config_output(&DDRC, LED_RED);
      GPIO_write_high(&PORTC, LED_RED);
      /* push button */
      GPIO_config_input_pullup(&DDRD, BTN);
  
      // Infinite loop
      while (1)
      {
          // Pause several milliseconds
          _delay_ms(BLINK_DELAY);
  		if(!GPIO_read(&PIND, BTN))
  		{
  			GPIO_toggle(&PORTB, LED_GREEN);
  			GPIO_toggle(&PORTC, LED_RED);			
  		}
  
      }
  
      // Will never reach this
      return 0;
  }