From b89a708807c72c67b128aa3d684afdbd694f66bc Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Mon, 24 Feb 2014 15:32:57 +0100 Subject: Add simple timer that counts one second --- main.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 6bda270..4a65c84 100644 --- a/main.c +++ b/main.c @@ -10,6 +10,7 @@ #include "i2c.h" #include "uart.h" +#include "timer.h" static void ledInit () { /* set led1,led2 to output */ @@ -31,13 +32,6 @@ static void cpuInit () { CLKPR = 0b00000011; } -volatile unsigned char count; - -ISR(TIMER0_OVF_vect) { - ++count; - //printf ("timer interrupt hit, count now %u\n", count); -} - #define sleepwhile(cond) \ sleep_enable (); \ while (cond) { sleep_cpu (); } \ @@ -61,30 +55,24 @@ int main () { sleepwhile (twr.status == TWST_WAIT); printf ("final twi status was %i\n", twr.status); + timerStart (); + unsigned char seconds = 0; while (1) { uint8_t val[6]; + + sleepwhile (!timerHit ()); + ++seconds; + printf ("running for %u seconds\n", seconds); + if (!twReadMulti (LIS302DL, 0x28, val, 6)) { printf ("cannot start read\n"); } sleepwhile (twr.status == TWST_WAIT); - printf ("%i/%i/%i\n", (int8_t) val[1], (int8_t) val[3], (int8_t) val[5]); - - count = 0; - /* set normal mode timer0 */ - TCCR0A = 0; - /* io clock with 1024 prescaler */ - TCCR0B = (TCCR0B & ~((1 << CS01)) | (1 << CS02) | (1 << CS00)); - /* enable overflow interrupt */ - TIMSK0 = (1 << TOIE0); - - sleepwhile (count < 3); - - /* stop timer (zero clock source) */ - TCCR0B = 0; - - /* XXX: why do we need the delay here? */ - //_delay_ms (250); + printf ("%i/%i/%i\n", (int8_t) val[1], (int8_t) val[3], + (int8_t) val[5]); } + timerStop (); + /* global interrupt disable */ cli (); -- cgit v1.2.3