Skip to content

Instantly share code, notes, and snippets.

@avr-programmierung
Created May 14, 2019 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avr-programmierung/f7aa9b75b210535dd6633f17c4d98ca4 to your computer and use it in GitHub Desktop.
Save avr-programmierung/f7aa9b75b210535dd6633f17c4d98ca4 to your computer and use it in GitHub Desktop.
ATmega88 @ 1MHz LED on/off
/* 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