#include <avr/io.h>
#include <inttypes.h>
#include <avr/interrupt.h>
#include <avr/signal.h>

typedef unsigned char BYTE;
typedef unsigned short WORD;

BYTE byte_timer;

void timer_init(void)
{
/*Clear Timer on Compare Match (Initialwert des Bits ist 0)
Wenn dieses Bit gesetzt ist wird nach Übereinstimmung des Datenregisters mit dem
Vergleichswert das Datenregister auf 0 gesetzt.

Clock Select Bits (Intitialwerte der Bits sind alle 0)
Diese 3 Bits bestimmen die Quelle für den Timer
CS10(Bit 0) CS11(Bit 1) CS12(Bit 2) Aktion
0 0 0 Timer wird angehalten
1 0 0 CPU-Takt
0 1 0 CPU-Takt/8
1 1 0 CPU-Takt/64
0 0 1 CPU-Takt/256
1 0 1 CPU-Takt/1024
0 1 1 Externer Pin T0, fallende Flanke
1 1 1 Externer Pin T0, steigende Flanke*/
TCCR1B|=(1<<CS10)|(1<<CS12)|(1<<CTC1);

/*Output Compare Match Interupt Enable (Initialwert des Bits ist 0)
Wenn dieses Bit gesetzt ist wird beim erreichen des Vergleichswertes ein Interupt ausgelöst.*/
TIMSK|=(1<<OCIE1A);

/*Output Compare Register beschreiben*/
cli();
OCR1=15625;

/*Timer Datenregister zurrücksetzen*/
TCNT1=0;
sei();
}

SIGNAL(SIG_OUTPUT_COMPARE)
{
cli();
/*Timer anhalten*/
TCCR1B&=~((1<<CS10)|(1<<CS12));
byte_timer=1;
}

int main(void)
{
/*Alle LEDs als Ausgänge*/

DDRA=0xFF;
DDRB=0xFF;
DDRC=0xFF;
DDRD=0xFF;
DDRE=0xFF;
DDRF=0xFF;
DDRG=0xFF;

/*Alle LEDs an PORTA an bis auf die letzte,alle LEDs an PORTD auf
bis auf die letzte und alle LEDs an PORTG an.*/

PORTA=0x7E;
PORTB=0x80;
PORTC=0x0;
PORTD=0x0;
PORTE=0x0;
PORTF=0x0;
PORTG=0xFF;

/*Led 0,2,4 an PORTA aus*/

PORTA&=~((1<<DDA0)|(1<<DDA2)|(1<<DDA4));

timer_init();
while(byte_timer=0){}

/*LED 0,2,4 an PORTB an*/

PORTB|=((1<<DDB0)|(1<<DDB2)|(1<<DDB4));

while(1){}
}



> "make.exe" all

-------- begin --------
avr-gcc (GCC) 3.4.1
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Size before:
test.elf :
section size addr
.data 0 8388864
.text 268 0
.bss 0 8388864
.noinit 0 8388864
.eeprom 0 8454144
.stab 756 0
.stabstr 1240 0
Total 2264




Compiling: test.c
avr-gcc -c -mmcu=atmega128 -I. -gstabs -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=test.lst -std=gnu99 -Wp,-M,-MP,-MT,test.o,-MF,.dep/test.o.d test.c -o test.o
test.c: In function `timer_init':
test.c:28: error: `CTC1' undeclared (first use in this function)
test.c:28: error: (Each undeclared identifier is reported only once
test.c:28: error: for each function it appears in.)
test.c:36: error: `OCR1' undeclared (first use in this function)
test.c: In function `main':
test.c:79: warning: suggest parentheses around assignment used as truth value
make.exe: *** [test.o] Error 1

> Process Exit Code: 2


So das sind die fehler die noch auftauchen ... naja CTC1 müsste es eigentlich geben stand in dem Tut von Microcontroller.net/wiki drin ist clear timer on compare match und OCR1 ist das Output Compare register ...