aboutsummaryrefslogtreecommitdiff
path: root/software/inc/int/dcf77.c
diff options
context:
space:
mode:
Diffstat (limited to 'software/inc/int/dcf77.c')
-rwxr-xr-xsoftware/inc/int/dcf77.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/software/inc/int/dcf77.c b/software/inc/int/dcf77.c
new file mode 100755
index 0000000..31f1663
--- /dev/null
+++ b/software/inc/int/dcf77.c
@@ -0,0 +1,123 @@
1// vim:set et sw=2 ts=2 tw=120:
2#include "dcf77.h"
3
4// 7372800/a=10000
5// 115200 / a * x = 10000
6// 7372800/8/150
7
8// returns -1 on error
9unsigned char getBits(const DCF start, const char len)
10{
11 static const unsigned char mult[] = {1, 2, 4, 8, 10, 20, 40, 80};
12 /// unsigned char p = 1; //parity
13 unsigned char r = 0; // retval
14 unsigned char i;
15 for(i=0; i<len; i++)
16 r += dcf77[start+i].bit * mult[i];
17 /// if(dcf77[start+i].bit)
18 /// p ^= 1;
19 return r;
20}
21
22// interrupt service routine (ISR) for timer 0 A compare match
23ISR(TIMER0_COMPB_vect)
24{
25
26}
27
28// ISR(TIMER0A_COMP_vect)
29ISR(TIMER0_COMPA_vect)
30{
31 interval++;
32 if (++t_current.ms >= 1000) // one second
33 {
34 t_current.ms = 0; // restart
35 if (++t_current.s > 59) // one minute
36 {
37 t_current.s = 0; // restart
38 if (++t_current.m > 59) // one hour
39 {
40 t_current.m = 0; // restart
41 if (++t_current.h > 23) // one day
42 {
43 t_current.h = 0; // restart
44 t_current.dd++;
45 }
46 }
47 }
48 }
49}
50
51ISR(INT0_vect)
52{
53}
54
55ISR(PCINT0_vect)
56{
57 // if(INT0_CONTROL == INT0_RISING_EDGE)
58 // if(MCUCR & (1<<ISC00))
59 // {
60 if (interval > 1000 && interval < 2000) // 59th second - no rising edge at the beginning
61 {
62 if(dcf77_bit == 59) // check if every bit has been transfered
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 }
71
72 // 59th second: synchronize with receiver...
73 dcf77_bit = 0;
74 t_current.s = 0;
75 t_current.ms = 0;
76
77 // falling edge causes interrupt...
78 // INT0_CONTROL = INT0_FALLING_EDGE;
79 }
80 else // INT0_FALLING_EDGE
81 {
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;
86
87 // rising edge causes interrupt...
88 // INT0_CONTROL = INT0_RISING_EDGE;
89 }
90
91 TCNT0 = 0;
92 interval = 0;
93}
94
95/*
96void timer_init()
97{
98 // 7372800/8
99 // >>>>>> DDRD &= ~((1<<PD2) | (1<<PD3)); // make INT0 and INT1 input-pins
100
101 // Prescaler...
102 // output compare...
103
104 //OCR0 = 152 - 1;
105 //TCCR0 |= (0<<WGM01) | (1<<WGM01);
106
107 // ICNC1 (Input Capture Noise Canceler (4 CKs) Timer/Counter 1
108 // ICES1 (Input Capture Edge Select Timer/Counter 1) - 1:increasing 0:falling
109 // CSx: set prescaler (010 means 8)
110 /// TCCR1B = (1<<ICNC1) | (1<<ICES1) | (0<<CS12) | (1<<CS11) | (0<<CS10);
111 // OCIE0: Output Compare Match Interrupt Enable
112 // TICIE: Timer/Counter Input Capture Interrupt Enable
113
114 // interrupts_init...
115 // General Interrupt Mask Register (enables interrupts)
116 GIMSK |= (1<<INT0);
117 // GICR |= (1<<INT0);
118 // MCU Control Register (controls CPU-behaviours like interrupts & sleepmode)
119 MCUCR |= (1<<ISC01) | (1<<ISC00); // any logical change generates interrupt
120 INT0_CONTROL = INT0_RISING_EDGE; // going to toggle int0-behaviour
121 /// loworhigh.bit = 0;
122}
123*/
..