Simple single-color 8x8x8 LED Cube with AVRs
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

time.c 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * time.c
  3. *
  4. * Copyright 2012 Thomas Buck <xythobuz@me.com>
  5. *
  6. * This file is part of LED-Cube.
  7. *
  8. * LED-Cube is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * LED-Cube is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <stdlib.h>
  22. #include <stdint.h>
  23. #include <avr/io.h>
  24. #include <avr/interrupt.h>
  25. #include "time.h"
  26. // Uses Timer 0!
  27. // Interrupt:
  28. // Prescaler 64
  29. // Count to 250
  30. // => 1 Interrupt per millisecond
  31. volatile uint64_t systemTime = 0; // Overflows in 500 million years... :)
  32. void initSystemTimer() {
  33. TCCR0 |= (1 << WGM01) | (1 << CS01) | (1 << CS00); // Prescaler: 256, CTC Mode
  34. OCR0 = 250;
  35. TIMSK |= (1 << OCIE0); // Enable overflow interrupt
  36. }
  37. ISR(TIMER0_COMP_vect) {
  38. systemTime++;
  39. }
  40. uint64_t getSystemTime() {
  41. return systemTime;
  42. }