Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3. #include <util/delay.h>
  4.  
  5. double dutyCycle = 0;
  6.  
  7. int main(void)
  8. {
  9. DDRD = (1 << PORTD6);
  10.  
  11. TCCR0A = (1 << COM0A1) | (1 << WGM00) | (1 << WGM01);
  12. TIMSK0 = (1 << TOIE0);
  13.  
  14. OCR0A = (dutyCycle/100)*255.0;
  15.  
  16. sei();
  17.  
  18. TCCR0B = (1 << CS00) | (1 << CS02);
  19.  
  20. while(1)
  21. {
  22.  
  23. _delay_ms(1000);
  24.  
  25. dutyCycle += 10;
  26.  
  27. if(dutyCycle > 100)
  28. {
  29. dutyCycle = 0;
  30. }
  31. }
  32. }
  33.  
  34. ISR(TIMER0_OVF_vect)
  35. {
  36. OCR0A = (dutyCycle/100.0)*255;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement