/* * time.c * * Created on: 20.05.2014 * Author: wn */ #include #include #include #include "time.h" volatile unsigned long timestamp; Uptime uptime; ISR(TIMER0_A0, TA0_ISR) { static uint8_t state = 0; timestamp++; switch (state) { case 0: P1OUT = BIT0; state = 1; break; case 1: P1OUT = BIT6; state = 0; break; default: state = 0; } } void timeInit() { timestamp = 0; P1DIR |= BIT6 | BIT0; P1OUT = 0; TACCR0 = 1024; TACCTL0 = CCIE; TACTL = MC_1 | ID_3 | TASSEL_1 | TACLR; } unsigned long millis() { return timestamp; } Uptime::Uptime() : m_seconds(0), m_minutes(0), m_hours(0), m_days(0) { } void Uptime::incOneSecond() { m_seconds++; if (m_seconds >= 60) { m_seconds -= 60; m_minutes++; if (m_minutes >= 60) { m_minutes -= 60; m_hours++; if (m_hours >= 24) { m_hours -= 24; m_days++; } } } }