Skip to content

Instantly share code, notes, and snippets.

@avr-programmierung
Created May 16, 2019 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avr-programmierung/afce3048ff28e2663ef97740277e4450 to your computer and use it in GitHub Desktop.
Save avr-programmierung/afce3048ff28e2663ef97740277e4450 to your computer and use it in GitHub Desktop.
ATmega88 @ 8MHz LED fading 01
/* 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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment