Advertisement
Guest User

Untitled

a guest
May 28th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3. #include <avr/sleep.h>
  4.  
  5. // seconds counter
  6. volatile uint8_t sec;
  7. // minutes counter
  8. volatile uint8_t min;
  9.  
  10. ////////////////////////////////////////////////////////
  11. //
  12. // clock frequency = 4MHz
  13. //
  14. // 64 = prescaler clock
  15. //
  16. ////////////////////////////////////////////////////////
  17.  
  18. int main(void){
  19. sec = 0; min = 0;
  20. // Set up CTC mode
  21. // Timer1 Control Register A
  22. TCCR1A |= 0;
  23. // Timer1 Control Register B
  24. // Prescaler = 64
  25. TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10);
  26.  
  27. // Initialize Compare Value
  28. OCR1A = 62499;
  29.  
  30. // Timer Interrupt Mask Register (common)
  31. // enable T1 compare interrupts
  32. TIMSK |= _BV(OCIE1A) | _BV(OCIE1B);
  33.  
  34. sei(); // enable global interrupts
  35.  
  36. while (1) {
  37. // just sleep while waiting
  38. sleep_enable();
  39. sleep_cpu();
  40. sleep_disable();
  41. }
  42.  
  43. return 0;
  44. }
  45.  
  46. ISR (TIMER1_COMPA_vect) {
  47. if(++sec >= 60) {
  48. sec = 0;
  49. min++;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement