a500kbd

view src/timer.c @ 3:31a1f0b53d98

- scroll lock now acts as caps lock - the scroll-lock light indicates drive activity
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 18 Oct 2017 08:20:58 +0300
parents
children
line source
1 #include <avr/io.h>
2 #include <avr/interrupt.h>
3 #include <avr/power.h>
4 #include "timer.h"
6 #define PRESCL_256 4
7 /* 256 ticks per interrupt, 256 clock divisor */
8 #define TICKS_PER_SEC (F_CPU / 256 / 256)
10 static volatile unsigned long ticks;
12 void init_timer(void)
13 {
14 power_timer0_enable();
16 TCCR0A = 0;
17 TCCR0B = PRESCL_256;
19 TIMSK0 |= (1 << TOIE0); /* enable ovf intr. */
20 }
22 void reset_timer(void)
23 {
24 ticks = 0;
25 }
27 unsigned long get_msec(void)
28 {
29 return 1000 * ticks / TICKS_PER_SEC;
30 }
32 ISR(TIMER0_OVF_vect)
33 {
34 ++ticks;
35 }