Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. static inline void initTimer0(void) {
  2. // Timer Counter Control Register B
  3. // Must b4 /64 or more for ISR timing
  4. TCCR0B |= (1 << CS00) | (1 << CS01);
  5.  
  6. // Timer Counter Interrupt Mask Register
  7. // both output compare interrupts
  8. TIMSK0 |= ((1 << OCIE0A) | (1 << OCIE1B));
  9.  
  10. // Timer Counter Overflow Interrupt Enable
  11. TIMSK0 |= (1 << TOIE0);
  12.  
  13. sei();
  14. }
  15.  
  16. /* Timer/Counter0 Overflow */
  17. // called whenever TCNT0 overflows
  18. ISR(TIMER0_OVF_vect) {
  19. PORTB |= (1 << 0);
  20. OCR0A = brightnessA;
  21. }
  22.  
  23. // ISR fired when a match occurs
  24. ISR(TIMER0_COMPA_vect) {
  25. PORTB ^= (1 << 0);
  26. }
  27.  
  28. int main(void)
  29. {
  30. setup();
  31. int d = 10;
  32.  
  33. while (1)
  34. {
  35. for (int i = 0; i < 255; i++) {
  36. _delay_ms(d);
  37. brightnessA = i;
  38. }
  39.  
  40.  
  41. }
  42. }
  43.  
  44. DDRB |= 1 << 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement