]> www.fi.muni.cz Git - bike-lights.git/blobdiff - tmr.c
lights.c split into more modules
[bike-lights.git] / tmr.c
diff --git a/tmr.c b/tmr.c
new file mode 100644 (file)
index 0000000..b8fb502
--- /dev/null
+++ b/tmr.c
@@ -0,0 +1,25 @@
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+#include "lights.h"
+
+volatile uint16_t jiffies;
+
+void init_tmr()
+{
+       TCCR0A = _BV(WGM00);
+       TCCR0B = _BV(CS02) | _BV(CS00); // CLK/1024 = 1 kHz
+       OCR0A = 10; // 100 Hz
+       TIMSK |= _BV(OCIE0A);
+
+       jiffies = 0;
+}
+
+ISR(TIMER0_COMPA_vect)
+{
+       ++jiffies;
+
+       // patterns_next_tick();
+       timer_start_adcs();
+}
+