Skip to content

Instantly share code, notes, and snippets.

@theresalu
Created April 1, 2015 08:51
Show Gist options
  • Save theresalu/89e774dbac597cb840e5 to your computer and use it in GitHub Desktop.
Save theresalu/89e774dbac597cb840e5 to your computer and use it in GitHub Desktop.
Timer2; 32,768kHz; PS=256; ATMega8
#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