#include <avr/io.h>
#include <util/delay.h>
int main()
{
//variable declarations
bool lastBtn = 0;
// set pb7 as output
DDRB |= 0x01 << 7; // "Setzen eines Bit", Bit 7 wird ODER verknüpft
//die restlichen Bit werden ODER verknüpft mit 1
// set pb6 as input;
DDRB &= ~(0x01 << 6); // "Löschen eines Bit" ~ -> invertieren
// nur Bit 6 wird & mit 0 verknüpft, die restlichen Bit mit 1
// activate internal pullup resitor on pb6
PORTB |= 0x01 << 6; // "Setzen eines Bit"
while(1)
{
// test pb6, ob der Taster gedrückt ist
bool btn = ((PINB >> 6) & 0x01) == 0x00;
// when btn pressed, toggle led 0^=0 = 0, 0^=1 = 1, 1^=0 = 1, 1^=1 = 0
//XOR, exklusives oder
//toggle led at rising edge, wenn lastBtn = 0 ist und btn = 1 wird.
if (btn==1 && lastBtn==0)
{
PORTB ^= (0x01 << 7);
}
//remember last button state
lastBtn = btn;
}
}