Advertisement
Guest User

Coolpales Comment maxEmbedded

a guest
May 19th, 2013
4,834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3. #include <avr/interrupt.h>
  4.  
  5. volatile uint8_t count = 0;
  6.  
  7. void timer1_init ()
  8. {
  9. OCR1A = 57599;
  10. TIMSK |= 16; //Output compare interrupt enable
  11. TCCR1B |= (1<<CS12) | (1<<WGM12); //256x pre-scaler
  12. sei(); //global interrupt enable
  13. }
  14.  
  15. ISR (TIMER1_COMPA_vect)
  16. {
  17. if (count)
  18. {
  19. count = 0;
  20. PORTB |= (1<<PB0);
  21. OCR1A = 633;
  22. }
  23. else
  24. {
  25. count = 1;
  26. PORTB &= ~(1<<PB0);
  27. OCR1A = 518;
  28. }
  29. }
  30.  
  31. int main(void)
  32. {
  33. PORTB = 0b00;
  34. DDRB |= (1<<PB0) | (1<<PB1);
  35. timer1_init();
  36.  
  37. while(1);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement