// https://arbaranwal.github.io/tutorial/2017/06/23/atmega328-register-reference.html
// https://playground.arduino.cc/Code/BitMath/
// https://stackoverflow.com/questions/13704076/passing-a-port-as-a-variable-avr
#include <avr/io.h>
volatile uint8_t* LED_DDR;
volatile uint8_t* LED_PORT;
void LED(volatile uint8_t* port, uint8_t pin) {
LED_DDR = (port - 1);
LED_PORT = port;
// the variable port is a pointer that means the address of PORTD ==> (&PORTD)
// (port -1) sets DDRx-address (is one address below PORT address)
// *(port -1) the "*" points to the contents of DDRx
// (1 << pin) setting the bit of a certain pin
// *(port -1) |= (1 << pin);
// *(LED_PORT -1) |= (1 << pin);
*LED_DDR |= (1 << pin);
// set the pin high, pin is usual like "PD5"
// *port |= (1<< pin);
*LED_PORT |= (1<< pin);
}
int main(void) {
// calling the function LED with option PORT-address &PORTD
// with option pin PD4
LED(&PORTD, PD5);
while (1) {
}
}