Created
May 14, 2019 10:17
-
-
Save avr-programmierung/f7aa9b75b210535dd6633f17c4d98ca4 to your computer and use it in GitHub Desktop.
ATmega88 @ 1MHz LED on/off
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* led_on_off_01.c ATmega88 @ 1MHz */ | |
#include <avr/io.h> | |
#include <util/delay.h> | |
#define button_down !(PIND & (1<<PIND2)) // Taster = low | |
#define led_toggle PORTB ^= (1<<PB0) // PB0 toggle | |
int main(void) | |
{ | |
DDRB = 0xFF; // PORTB = Ausgang | |
DDRD = ~(1<<PIND2); // PORTD PIN0 = Eingang | |
while(1) | |
{ | |
if (button_down) // Wenn Taster gedrückt ist | |
{ | |
_delay_ms(20); // Prellzeit nach Tastendruck abwarten | |
if (!button_down) // Wenn Taster losgelassen ist | |
{ | |
led_toggle; // LED ON/OFF | |
_delay_ms(20); // Prellzeit nach dem Loslassen des Tasters abwarten | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment