Naze32 clone with Frysky receiver
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

timer.c 513B

123456789101112131415161718192021222324252627
  1. /*
  2. * Time-Keeping helper
  3. */
  4. #include <avr/io.h>
  5. #include <avr/interrupt.h>
  6. #include "timer.h"
  7. volatile time_t systemTime = 0;
  8. void timerInit(void) {
  9. // Using 8bit Timer1
  10. TCCR1 |= (1 << CTC1); // CTC Mode
  11. TCCR1 |= (1 << CS12) | (1 << CS11) | (1 << CS10); // Prescaler: 64
  12. OCR1A = 250; // Count to 250
  13. TIMSK |= (1 << OCIE1A); // Enable compare match interrupt
  14. }
  15. ISR(TIMER1_COMPA_vect) {
  16. systemTime++; // one millisecond has passed
  17. }
  18. time_t timerGet(void) {
  19. return systemTime;
  20. }