ATmega88 @ 8MHz LED fading 01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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