/* LED_fading_01.c ATmega88 @ 8MHz */
#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
	DDRB |= (1<<PB1);	// OC1A = output
	ICR1 = 1000;		// Top Value = 1000
	OCR1A = 750;		// Compare Match bei 750
	
	// Mode 10: PWM, Phase Correct, Prescaler = 8, Clear OC1A on compare match
	TCCR1A = (1 << COM1A1) + (1 << WGM11);
	TCCR1B = (1 << WGM13) + (1 << CS11);
	
	while(1)
	{
		for (int i=0; i<=999; i++)		// OCR1A in 10ms Schritten bis 1000 inkrementieren
		{
			OCR1A = i;
			_delay_ms(10);
		}
		
		for (int i=1000; i>=1; i--)		// OCR1A in 10ms Schritten bis 0 dekrementieren
		{
			OCR1A = i;
			_delay_ms(10);
		}
	}
}