From 02f25d07834ae1ff95e3d625bef0791efc6ca0b8 Mon Sep 17 00:00:00 2001 From: wolfgang Date: Tue, 22 Jan 2013 07:58:08 +0100 Subject: [PATCH] led --- src/main.c | 69 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/src/main.c b/src/main.c index 54a7c9a..f6fb360 100644 --- a/src/main.c +++ b/src/main.c @@ -12,6 +12,8 @@ #define ZERO_WIDTH_MIN 70 #define ZERO_WIDTH_MAX 150 +#define SUB_DIV_VAL 30 + typedef struct receivedData_s { uint8_t minuteDigit0; @@ -55,7 +57,7 @@ volatile uint8_t tick; volatile uint16_t captValue = 0; volatile uint16_t gapValue = 0; volatile uint8_t valid = 0; - +volatile uint8_t tack = 0; ISR(TIMER2_OVF_vect) { clock.second++; @@ -77,17 +79,17 @@ ISR(TIMER2_OVF_vect) { opTime.second++; - if (opTime.second >= 60) { - opTime.second = 0; - opTime.minute++; - } - if (opTime.minute >= 60) { - opTime.minute = 0; - opTime.hour++; - } - if (opTime.hour >= 24) { - opTime.hour = 0; - } + if (opTime.second >= 60) { + opTime.second = 0; + opTime.minute++; + } + if (opTime.minute >= 60) { + opTime.minute = 0; + opTime.hour++; + } + if (opTime.hour >= 24) { + opTime.hour = 0; + } } ISR(INT0_vect) { @@ -101,6 +103,14 @@ ISR(INT1_vect) { tick = 1; } +ISR(TIMER0_OVF_vect) { + static uint16_t subDiv = 0; + subDiv++; + if (subDiv >= SUB_DIV_VAL) { + subDiv = 0; + tack = 1; + } +} int main() { uartdrvInit(); @@ -123,10 +133,16 @@ int main() { TCCR1A = 0; TCCR1B = (1 << CS12) | (1 << CS10); - PIND &= ~(1 << PD2); - PIND &= ~(1 << PD3); + DDRD &= ~(1 << PD2); + DDRD &= ~(1 << PD3); PORTD |= (1 << PD2) | (1 << PD3); + DDRD |= (1 << PD5) | (1 << PD6); + + DDRB |= (1 << PB0); + TCCR0 = (1 << CS02) | (1 << CS00); + TIMSK |= (1 << TOIE0); + MCUCR |= (1 << ISC11) | (1 << ISC10) | (1 << ISC01); GICR |= (1 << INT0) | (1 << INT1); @@ -139,6 +155,7 @@ int main() { uint8_t bit = 0; uint8_t state = 0; uint16_t validCnt = 0; + uint8_t ledToggle = 0; while (1) { @@ -466,6 +483,30 @@ int main() { valid, state, bit, pulse, gap, validCnt); } } + + + if (tack != 0) { + tack = 0; + switch (valid) { + case 0: + PORTB &= ~(1 << PB0); + break; + case 1: + if (ledToggle != 0) { + ledToggle = 0; + PORTB &= ~(1 << PB0); + } else { + ledToggle = 1; + PORTB |= (1 << PB0); + } + break; + case 2: + PORTB |= (1 << PB0); + break; + } + } + } + }