Created
May 14, 2019 10:29
-
-
Save avr-programmierung/622df02bffa04e6e8219eccbdb03860d to your computer and use it in GitHub Desktop.
ATmega88 @ 1MHz interrupt 02
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
/* interrupt_02.c ATmega88 @ 1MHz */ | |
#include <avr/io.h> | |
#include <avr/interrupt.h> // Einbinden der Headerdatei für Interrupts | |
uint8_t flag=0; // Globale Variable flag | |
uint8_t count=0; // Globale Variable count | |
int main(void) | |
{ | |
DDRD &= ~(1<<PD2); // PD2 = Eingang (INT0) | |
DDRB |= (1<<PB1); // PB1 = Ausgang | |
PORTB = 0x00; // PORTB auf low | |
EICRA |= (1<<ISC01)|(1<<ISC00); // Int0 wird durch eine steigende Flanke ausgelöst | |
EIMSK |= (1<<INT0); // Ext. Int0 aktivieren | |
sei(); // Alle Interrupts aktivieren | |
while(1) | |
{ | |
if(flag == 1) | |
{ | |
count ++; | |
PORTB = count; // PORTB ++ | |
flag = 0; // flag löschen | |
} | |
} | |
return 0; | |
} | |
ISR (INT0_vect) // Hier beginnt die ISR für den ext. Int0 | |
{ | |
flag = 1; // flag setzen | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment