Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2015
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. #include
  2. void timer0_init()
  3. {
  4. //Toggle 0C0A on compare match
  5. TCCR0A |= (1 << COM0A0);
  6. //No prescaler, CTC mode
  7. TCCR0B |= (1 << WGM01)|(1 << CS00);
  8. //Initialize counter
  9. TCNT0 = 0;
  10. //Compare register value set to 199 for 40kHz
  11. OCR0A = 199;
  12. }
  13. int main(void)
  14. {
  15. //PD0 output
  16. DDRD = 0b00000001;
  17. timer0_init();
  18. while(1)
  19. {
  20. //switch PD0 high when compare match
  21. if (OCF0A == 1)
  22. {
  23. //PD0 HIgh
  24. PORTD = 0b00000001;
  25. }
  26. //Disable interupt when match occur
  27. TIFR0 = OCF0A;
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement