Advertisement
Guest User

Untitled

a guest
May 26th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. /* LED_fading_01.c ATmega88 @ 8MHz */
  2. #include <avr/io.h>
  3. #include <util/delay.h>
  4.  
  5. int main(void)
  6. {
  7. DDRB |= (1<<PB1); // OC1A = output
  8. ICR1 = 1000; // Top Value = 1000
  9. OCR1A = 750; // Compare Match bei 750
  10.  
  11. // Mode 10: PWM, Phase Correct, Prescaler = 8, Clear OC1A on compare match
  12. TCCR1A = (1 << COM1A1) + (1 << WGM11);
  13. TCCR1B = (1 << WGM13) + (1 << CS11);
  14.  
  15. while(1)
  16. {
  17. for (int i=0; i<=999; i++) // OCR1A in 10ms Schritten bis 1000 inkrementieren
  18. {
  19. OCR1A = i;
  20. _delay_ms(10);
  21. }
  22.  
  23. for (int i=1000; i>=1; i--) // OCR1A in 10ms Schritten bis 0 dekrementieren
  24. {
  25. OCR1A = i;
  26. _delay_ms(10);
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement