Created
April 1, 2015 08:51
-
-
Save theresalu/89e774dbac597cb840e5 to your computer and use it in GitHub Desktop.
Timer2; 32,768kHz; PS=256; ATMega8
This file contains hidden or 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
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
volatile uint8_t count=0; // Zählvariable; volatile= compiler optimiert Variable nicht (keine Konstante) | |
volatile uint8_t sekunde=0; | |
void main() | |
{ | |
TCCR2|=(1<<CS22)|(1<<CS20); | |
TIMSK|=(1<<TOIE2); | |
ASSR|=(1<<AS2); | |
sei(); // global Interrupts erlauben ; alle ints ausschalten:cli(); | |
DDRD=0xF; // Port als Ausgang | |
while(1); // Schleife, damit Controller weiterläuft | |
} | |
ISR(TIMER2_OVF_vect) // interrupt service routine; avr-libc S.241 | |
{ | |
TCNT0=0; // | |
sekunde++; | |
PORTD=sekunde; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment