Advertisement
Guest User

Untitled

a guest
Mar 29th, 2014
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. /*
  2.  * a way of keeping track of time.
  3.  * by darrel
  4.  * */
  5.  
  6. //Time tracking related
  7. unsigned long time = 0; //Stores the time in fifth of seconds
  8. unsigned long timeinSeconds = 0; //stores the time in seconds
  9.  
  10. void initTime()
  11. {
  12.     //setup to tick once a second.
  13.     TCCR0A |= (1<<WGM01); //ctc mode (clear on timer compare)
  14.     TCCR0B |= (1<<CS00)|(1<<CS02); //set prescaler to 1024
  15.     TIMSK0 |= (1<<OCIE0A); //enable interupt on compare
  16.     OCR0A = 198;
  17.     sei(); //enable global interupts.
  18. }
  19.  
  20. ISR(TIMER0_COMPA_vect)
  21. {
  22.     //increment every 1/5 a second.
  23.     time++;
  24.     timeinSeconds = time/5;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement