Skip to content

Instantly share code, notes, and snippets.

@avr-programmierung
Created May 14, 2019 10:15
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/c441c17c1a1ed96f301cc0f0bf5815a4 to your computer and use it in GitHub Desktop.
Save avr-programmierung/c441c17c1a1ed96f301cc0f0bf5815a4 to your computer and use it in GitHub Desktop.
ATmega88 @ 1MHz Binärzähler
/* binaerzaehler_01.c ATmega88 @ 1MHz */
#include <avr/io.h>
#include <avr/delay.h>
int main(void)
{
DDRB = ~(1<<PB6); // PinB6 = Eingang
DDRC |= 0xFF; // PORTC = Ausgang
while(1)
{
if (!(PINB & (1<<PINB6))) // Wenn Taster an PB6 = gedrückt (LOW)
{
_delay_ms(20); // 20ms Prellzeit nach Tastendruck abwarten
if (PINB & (1<<PINB6)) // Wenn Taster an PB6 = losgelassen (HIGH)
{
_delay_ms(20); // 20ms Prellzeit nach dem Loslassen des Tasters abwarten
PORTC ++; // PORTC um 1 erhöhen
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment