From 517d5896503d75132a74fccd8f9a79ea01a7c829 Mon Sep 17 00:00:00 2001 From: Lea Date: Tue, 29 Aug 2023 18:52:13 +0200 Subject: [PATCH] interrupts but real --- main.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index d7eaf66..de4f1f2 100644 --- a/main.c +++ b/main.c @@ -10,19 +10,20 @@ #include "lib/7segment.h" #include "lib/7segment_4digits.h" -volatile int ticks = 0; +int timer_start = 0xffff - (F_CPU / 1024 / 1000); +volatile uint32_t ticks = 0; // https://gist.github.com/Wollw/2381139 void start_timer() { // Sets the Clock Select. See table on page 157 the Atmel datasheet. - TCCR1B |= _BV(CS10) | _BV(CS12); + TCCR1B |= _BV(CS10) | _BV(CS12); // clk/1024 // Set the TOIE (Timer Overflow Interrupt Enable) bit // on TIMSK1 (Timer 1 Interrupt Mask Register). TIMSK1 |= _BV(TOIE1); // Sets the current timer value - TCNT1 = 63974; + TCNT1 = timer_start; // Enable interrupts sei(); @@ -36,8 +37,8 @@ void main() { // ISR is used to handle interrupts. TIMER1_OVF_vect // is triggered whenever timer 1 (16 bit) overflows. ISR(TIMER1_OVF_vect) { - TCNT1 = 63974; // TODO figure out how to get the correct number - ticks++; + TCNT1 = timer_start; // TODO figure out how to get the correct number + ticks += 1; } void prog_7segment() { @@ -76,7 +77,7 @@ void prog_7segment_4digit() { bool pressed = false; while(1) { - show_float(ticks); + show_float(ticks / 1000.0f); float sleep_time = update_display(); if (!pressed && bit_is_clear(PINK, PINK7)) {