// arduino tutorial for this topic: https://docs.arduino.cc/retired/hacking/software/PortManipulation/
// documentation of Atmega 328p: https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf
#include <avr/io.h>
#include <util/delay.h>
int main(){
// diode configuration
DDRB |= (1<<DDB2) | (1<<DDB3) | (1<<DDB4) | (1<<DDB5); // Direction of port line (1 - output)
PORTB |= (1<<PORTB2) | (1<<PORTB3) | (1<<PORTB4) | (1<<PORTB5); // output value for output mode (1 - high do not light, 0 - lod light)
// BUTTON CONTROLLER
DDRD &= ~(1<<DDD0) | ~(1<<DDD1) | ~(1<<DDD2) | ~(1<<DDD3); // direction - input
PORTD |= (1<<PORTD0) | (1<<PORTD1) | (1<<PORTD2) | (1<<PORTD3); // pin to VCC (internal pullup)
while(1){
if (!(PIND & 1<<PIND3)) { // if S1 button is pressed counter up
PORTB = PORTB-1;
_delay_ms(100);
}
if (!(PIND & 1<<PIND2)) { // if S1 button is pressed counter up
PORTB = PORTB+1;
_delay_ms(100);
}
if (!(PIND & 1<<PIND1)) { // if S1 button is pressed counter up
PORTB = 255;
_delay_ms(100);
}
if (!(PIND & 1<<PIND0)) { // if S1 button is pressed counter up
PORTB = 0;
_delay_ms(100);
}
}
}