avrwristwatch/src/debug.c
Brett Weiland 7b006d6f20 init
2022-09-09 18:33:15 -05:00

32 lines
684 B
C

#include <avr/io.h>
#include <stdio.h>
#include <util/delay.h>
#include "debug.h"
/*
* TCNTn: timer/counter
* TCCRnA/B/C: timer/counter control registers
*/
void timer_init() {
TCCR1A = 0; //no waveform generation or something like that
TCCR1B = _BV(CS00); //no prescaling; use internal clock
TCCR1C = 0;
}
//makes it easier to print time; is an unsigned int and NOT to be used for more then printing
unsigned int ticks_to_seconds(uint16_t start, uint16_t end) {
return ((unsigned int)(end - start) / F_CPU);
}
void test_timer() {
uint16_t start, end;
start = TCNT1;
_delay_ms(1000);
end = TCNT1;
printf("1 second is %u ticks\n", end - start);
}