From 9cbb0d04bba30988d6e814726800444fa020e845 Mon Sep 17 00:00:00 2001 From: Max Christian Pohle Date: Fri, 26 May 2017 00:02:32 +0200 Subject: Time decoding works. --- inc/int/dcf77.c | 58 +++++++++++++++++++++------------------------------------ inc/int/dcf77.h | 15 +++++++-------- 2 files changed, 28 insertions(+), 45 deletions(-) (limited to 'inc') diff --git a/inc/int/dcf77.c b/inc/int/dcf77.c index 13af50d..31f1663 100755 --- a/inc/int/dcf77.c +++ b/inc/int/dcf77.c @@ -1,10 +1,14 @@ // vim:set et sw=2 ts=2 tw=120: #include "dcf77.h" +// 7372800/a=10000 +// 115200 / a * x = 10000 +// 7372800/8/150 + // returns -1 on error unsigned char getBits(const DCF start, const char len) { - static const unsigned char mult[] = {1, 2, 4, 8, 10, 20 ,40 ,80}; + static const unsigned char mult[] = {1, 2, 4, 8, 10, 20, 40, 80}; /// unsigned char p = 1; //parity unsigned char r = 0; // retval unsigned char i; @@ -15,32 +19,13 @@ unsigned char getBits(const DCF start, const char len) return r; } -void set_dcf_value() -{ - t_current.m = (getBits(DCF_MIN, 7)) - 1; - t_current.h = (getBits(DCF_HOUR, 6)); - t_current.dd = (getBits(DCF_DAY, 6)); - t_current.wd = (getBits(DCF_WEEKDAY, 3)); - t_current.mm = (getBits(DCF_MONTH, 5)); - t_current.yy = (getBits(DCF_YEAR, 8)); -} - -// 7372800/a=10000 -// 115200 / a * x = 10000 -// 7372800/8/150 - // interrupt service routine (ISR) for timer 0 A compare match -/* -ISR(TIMER0A_COMP_vect) // called 10000 times per second (12000000/8/150) -{ - -} -*/ ISR(TIMER0_COMPB_vect) { } +// ISR(TIMER0A_COMP_vect) ISR(TIMER0_COMPA_vect) { interval++; @@ -69,43 +54,42 @@ ISR(INT0_vect) ISR(PCINT0_vect) { - interval = 1; - /// stdout_put_int(interval, uart_putc); - /// stdout_put_string("INT0 call\n", uart_putc); - // cli(); - // if(INT0_CONTROL == INT0_RISING_EDGE) // if(MCUCR & (1< 1000 && interval < 2000) // 59th second - no rising edge at the beginning { - /// if(dcf77_bit == 59) // check if every bit has been transfered - // set_dcf_value(); // completely received- apply new time data + if(dcf77_bit == 59) // check if every bit has been transfered + { + t_current.m = getBits(DCF_MIN, 7); + t_current.h = getBits(DCF_HOUR, 6); + t_current.dd = getBits(DCF_DAY, 6); + t_current.wd = getBits(DCF_WEEKDAY, 3); + t_current.mm = getBits(DCF_MONTH, 5); + t_current.yy = getBits(DCF_YEAR, 8); + } // 59th second: synchronize with receiver... - TCNT0 = 0; dcf77_bit = 0; t_current.s = 0; t_current.ms = 0; - // t_current.us = 0; + // falling edge causes interrupt... - // MCUCR &= ~(1 << ISC00); - // MCUCR |= (1 << ISC01); // INT0_CONTROL = INT0_FALLING_EDGE; } else // INT0_FALLING_EDGE { - dcf77[dcf77_bit++].bit = interval >= 200 ? 1 : 0; + if(interval > 50 && interval < 150) + dcf77[dcf77_bit++].bit = 0; + else if(interval > 150 && interval < 250) + dcf77[dcf77_bit++].bit = 1; // rising edge causes interrupt... - // MCUCR |= (1 << ISC00); - // MCUCR |= (1 << ISC01); // INT0_CONTROL = INT0_RISING_EDGE; - // interval = 0; // reset interval to count next interval } + TCNT0 = 0; interval = 0; - // sei(); } /* diff --git a/inc/int/dcf77.h b/inc/int/dcf77.h index e47ca4e..2d79cdd 100755 --- a/inc/int/dcf77.h +++ b/inc/int/dcf77.h @@ -9,7 +9,6 @@ */ #include #include - #include #define INT0_CONTROL MCUCR @@ -26,14 +25,14 @@ typedef struct { - uint16_t h ; // hour - uint16_t m ; // minute - uint16_t s ; // second + uint16_t h; // hour + uint16_t m; // minute + uint16_t s; // second uint16_t ms; // milli second - uint8_t yy; // year - uint8_t mm; // month - uint8_t dd; // day - uint8_t wd; // weekday + uint8_t yy; // year + uint8_t mm; // month + uint8_t dd; // day + uint8_t wd; // weekday } Time; typedef enum -- cgit v1.2.3