Last active
August 29, 2015 14:18
-
-
Save theresalu/6dc269ce6097796e1030 to your computer and use it in GitHub Desktop.
Timer0; 8MHz; 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> | |
/* | |
125ns*256(PS)*250(GGT)*125(Zähler)=1 | |
*/ | |
volatile uint8_t count=0; // Zählvariable; volatile= compiler optimiert Variable nicht (keine Konstante) | |
void main() | |
{ | |
// Prescaler ATMega8 S.73 | |
//TCCR0&=~((1<<CS00)|(1<<CS01)); // Bits 0 setzen; restliches Register bleibt erhalten (nicht notwendig) | |
TCCR0|=(1<<CS02); // |= ODER (setzen); UND (löschen) | |
TIMSK|=(1<<TOIE0); // overflow interrupt aktivieren | |
sei(); // global Interrupts erlauben ; alle ints ausschalten:cli(); | |
while(1); // Schleife, damit Controller weiterläuft | |
} | |
ISR(TIMER0_OVF_vect) // interrupt service routine; avr-libc S.241 | |
{ | |
TCNT0=5; // 255-250 | |
count++; | |
if (count>=125) | |
{ | |
count=0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment