#include <util/delay.h>
// Macros that facilitate bitwise operation
#define READ_BIT(destiny, bit) (((destiny) >> (bit)) & 1)
#define SET_BIT(destiny, bit) (destiny) = (destiny) | (1 << (bit))
#define CLEAR_BIT(destiny, bit) (destiny) = (destiny) & ~(1 << (bit))
#define WRITE_BIT(destiny, value) (destiny) = (value) ? CLEAR_BIT((destiny), (bit)) : SET_BIT((destiny), (bit))
#define TOGGLE_BIT(destiny, bit) (destiny) = READ_BIT((destiny), (bit)) ? CLEAR_BIT((destiny), (bit)) : SET_BIT((destiny), (bit))
// Macro to make this cast more readable. C++ casts is more faster and safer.
#define REFERENCE_CAST *reinterpret_cast<uint8_t*>
// Using a reference instead of a pointer makes the code safer.
#define PORTB REFERENCE_CAST(0x25)
#define DDRB REFERENCE_CAST(0x24)
#define PINB REFERENCE_CAST(0x23)
int main(void){
SET_BIT(DDRB, 5); // Setting pin 13 as output
for(;;){
TOGGLE_BIT(PORTB, 5); // Toggling pin 13 state
_delay_ms(1000); // Delay
}
}