diff options
Diffstat (limited to 'inc')
-rwxr-xr-x | inc/int/dcf77.c | 58 | ||||
-rwxr-xr-x | inc/int/dcf77.h | 15 |
2 files changed, 28 insertions, 45 deletions
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 @@ | |||
1 | // vim:set et sw=2 ts=2 tw=120: | 1 | // vim:set et sw=2 ts=2 tw=120: |
2 | #include "dcf77.h" | 2 | #include "dcf77.h" |
3 | 3 | ||
4 | // 7372800/a=10000 | ||
5 | // 115200 / a * x = 10000 | ||
6 | // 7372800/8/150 | ||
7 | |||
4 | // returns -1 on error | 8 | // returns -1 on error |
5 | unsigned char getBits(const DCF start, const char len) | 9 | unsigned char getBits(const DCF start, const char len) |
6 | { | 10 | { |
7 | static const unsigned char mult[] = {1, 2, 4, 8, 10, 20 ,40 ,80}; | 11 | static const unsigned char mult[] = {1, 2, 4, 8, 10, 20, 40, 80}; |
8 | /// unsigned char p = 1; //parity | 12 | /// unsigned char p = 1; //parity |
9 | unsigned char r = 0; // retval | 13 | unsigned char r = 0; // retval |
10 | unsigned char i; | 14 | unsigned char i; |
@@ -15,32 +19,13 @@ unsigned char getBits(const DCF start, const char len) | |||
15 | return r; | 19 | return r; |
16 | } | 20 | } |
17 | 21 | ||
18 | void set_dcf_value() | ||
19 | { | ||
20 | t_current.m = (getBits(DCF_MIN, 7)) - 1; | ||
21 | t_current.h = (getBits(DCF_HOUR, 6)); | ||
22 | t_current.dd = (getBits(DCF_DAY, 6)); | ||
23 | t_current.wd = (getBits(DCF_WEEKDAY, 3)); | ||
24 | t_current.mm = (getBits(DCF_MONTH, 5)); | ||
25 | t_current.yy = (getBits(DCF_YEAR, 8)); | ||
26 | } | ||
27 | |||
28 | // 7372800/a=10000 | ||
29 | // 115200 / a * x = 10000 | ||
30 | // 7372800/8/150 | ||
31 | |||
32 | // interrupt service routine (ISR) for timer 0 A compare match | 22 | // interrupt service routine (ISR) for timer 0 A compare match |
33 | /* | ||
34 | ISR(TIMER0A_COMP_vect) // called 10000 times per second (12000000/8/150) | ||
35 | { | ||
36 | |||
37 | } | ||
38 | */ | ||
39 | ISR(TIMER0_COMPB_vect) | 23 | ISR(TIMER0_COMPB_vect) |
40 | { | 24 | { |
41 | 25 | ||
42 | } | 26 | } |
43 | 27 | ||
28 | // ISR(TIMER0A_COMP_vect) | ||
44 | ISR(TIMER0_COMPA_vect) | 29 | ISR(TIMER0_COMPA_vect) |
45 | { | 30 | { |
46 | interval++; | 31 | interval++; |
@@ -69,43 +54,42 @@ ISR(INT0_vect) | |||
69 | 54 | ||
70 | ISR(PCINT0_vect) | 55 | ISR(PCINT0_vect) |
71 | { | 56 | { |
72 | interval = 1; | ||
73 | /// stdout_put_int(interval, uart_putc); | ||
74 | /// stdout_put_string("INT0 call\n", uart_putc); | ||
75 | // cli(); | ||
76 | |||
77 | // if(INT0_CONTROL == INT0_RISING_EDGE) | 57 | // if(INT0_CONTROL == INT0_RISING_EDGE) |
78 | // if(MCUCR & (1<<ISC00)) | 58 | // if(MCUCR & (1<<ISC00)) |
79 | // { | 59 | // { |
80 | if (interval > 1000 && interval < 2000) // 59th second - no rising edge at the beginning | 60 | if (interval > 1000 && interval < 2000) // 59th second - no rising edge at the beginning |
81 | { | 61 | { |
82 | /// if(dcf77_bit == 59) // check if every bit has been transfered | 62 | if(dcf77_bit == 59) // check if every bit has been transfered |
83 | // set_dcf_value(); // completely received- apply new time data | 63 | { |
64 | t_current.m = getBits(DCF_MIN, 7); | ||
65 | t_current.h = getBits(DCF_HOUR, 6); | ||
66 | t_current.dd = getBits(DCF_DAY, 6); | ||
67 | t_current.wd = getBits(DCF_WEEKDAY, 3); | ||
68 | t_current.mm = getBits(DCF_MONTH, 5); | ||
69 | t_current.yy = getBits(DCF_YEAR, 8); | ||
70 | } | ||
84 | 71 | ||
85 | // 59th second: synchronize with receiver... | 72 | // 59th second: synchronize with receiver... |
86 | TCNT0 = 0; | ||
87 | dcf77_bit = 0; | 73 | dcf77_bit = 0; |
88 | t_current.s = 0; | 74 | t_current.s = 0; |
89 | t_current.ms = 0; | 75 | t_current.ms = 0; |
90 | // t_current.us = 0; | 76 | |
91 | // falling edge causes interrupt... | 77 | // falling edge causes interrupt... |
92 | // MCUCR &= ~(1 << ISC00); | ||
93 | // MCUCR |= (1 << ISC01); | ||
94 | // INT0_CONTROL = INT0_FALLING_EDGE; | 78 | // INT0_CONTROL = INT0_FALLING_EDGE; |
95 | } | 79 | } |
96 | else // INT0_FALLING_EDGE | 80 | else // INT0_FALLING_EDGE |
97 | { | 81 | { |
98 | dcf77[dcf77_bit++].bit = interval >= 200 ? 1 : 0; | 82 | if(interval > 50 && interval < 150) |
83 | dcf77[dcf77_bit++].bit = 0; | ||
84 | else if(interval > 150 && interval < 250) | ||
85 | dcf77[dcf77_bit++].bit = 1; | ||
99 | 86 | ||
100 | // rising edge causes interrupt... | 87 | // rising edge causes interrupt... |
101 | // MCUCR |= (1 << ISC00); | ||
102 | // MCUCR |= (1 << ISC01); | ||
103 | // INT0_CONTROL = INT0_RISING_EDGE; | 88 | // INT0_CONTROL = INT0_RISING_EDGE; |
104 | // interval = 0; // reset interval to count next interval | ||
105 | } | 89 | } |
106 | 90 | ||
91 | TCNT0 = 0; | ||
107 | interval = 0; | 92 | interval = 0; |
108 | // sei(); | ||
109 | } | 93 | } |
110 | 94 | ||
111 | /* | 95 | /* |
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 @@ | |||
9 | */ | 9 | */ |
10 | #include <avr/io.h> | 10 | #include <avr/io.h> |
11 | #include <avr/interrupt.h> | 11 | #include <avr/interrupt.h> |
12 | |||
13 | #include <stdint.h> | 12 | #include <stdint.h> |
14 | 13 | ||
15 | #define INT0_CONTROL MCUCR | 14 | #define INT0_CONTROL MCUCR |
@@ -26,14 +25,14 @@ | |||
26 | 25 | ||
27 | typedef struct | 26 | typedef struct |
28 | { | 27 | { |
29 | uint16_t h ; // hour | 28 | uint16_t h; // hour |
30 | uint16_t m ; // minute | 29 | uint16_t m; // minute |
31 | uint16_t s ; // second | 30 | uint16_t s; // second |
32 | uint16_t ms; // milli second | 31 | uint16_t ms; // milli second |
33 | uint8_t yy; // year | 32 | uint8_t yy; // year |
34 | uint8_t mm; // month | 33 | uint8_t mm; // month |
35 | uint8_t dd; // day | 34 | uint8_t dd; // day |
36 | uint8_t wd; // weekday | 35 | uint8_t wd; // weekday |
37 | } Time; | 36 | } Time; |
38 | 37 | ||
39 | typedef enum | 38 | typedef enum |