Skip to content

Instantly share code, notes, and snippets.

@theresalu
Last active August 29, 2015 14:18
Show Gist options
  • Save theresalu/6dc269ce6097796e1030 to your computer and use it in GitHub Desktop.
Save theresalu/6dc269ce6097796e1030 to your computer and use it in GitHub Desktop.
Timer0; 8MHz; PS=256; ATMega8
#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