1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#ifndef CLOCK_H
#define CLOCK_H
/* this dcf77-module relies on a accuarate clock (cristal) for receiving
* the dcf-signal. therefor the clock is going to work as expected,
* even with no dcf77-signal available.
* receivement is automatically turned on, if the avr is connected to the
* signal via INT0. if there is no signal the clock will not be set (K.I.S.S.)
*
*/
#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <limits.h>
/// #include "../stdout.h"
/// #include "../display/display.h"
/// #include "../uart/uart.h"
#define INT0_CONTROL MCUCR
#define INT0_FALLING_EDGE 0x02
#define INT0_RISING_EDGE 0x03
typedef struct
{
volatile unsigned char bit : 1;
} Bit;
typedef struct
{
unsigned char h ; // hour
unsigned char m ; // minute
unsigned char s ; // second
unsigned char dd; // day
unsigned char wd; // weekday
unsigned char mm; // month
unsigned char yy; // year
unsigned char us; // 10th second
unsigned int ms; // milli second
} Time;
typedef enum
{
DCF_FIRST = 0, // start of a new minute (note: always 0)
DCF_WEATHER = 14, // proprietary :-(
DCF_ANTENNA = 15, // 0: normal, 1: replacement
DCF_DST = 16, // daylight saving time: this hour new time...
DCF_MEZ = 17, // 'summer-time'
DCF_MESZ = 18, // 'winter-time'
DCF_DBLSEC = 19, // one extra second gonna be inserted
DCF_START = 20, // begin of time-info (note: always 1)
DCF_MIN = 21, // 7 bit
DCF_MINP = 28, // parity bit for minutes
DCF_HOUR = 29, // 6 bit
DCF_HOURP = 35, // parity bit for hours
DCF_DAY = 36, // 6 bit
DCF_WEEKDAY = 42, // 3 bit
DCF_MONTH = 45, // 5 bit
DCF_YEAR = 50, // 8 bit
DCF_DATEP = 58 // parity bit for date
} DCF;
/*
typedef struct
{
Bit useless[14];
Bit antenna;
Bit dst;
Bit mez;
Bit mesz;
Bit dblsec;
Bit start; // < always 1 - use for verification
unsigned char min : 7;
Bit min_p; // < minutes parity
unsigned char hour : 6;
Bit hour_p; // < hours parity
unsigned char day : 6; // day of month
unsigned char dow : 3; // day of week (1=monday)
unsigned char month : 5; // month of year
unsigned char year : 8; // year
Bit date_p; // parity of date
} DCF_Signal;
*/
volatile Bit dcf77[60];
volatile unsigned char dcf77_bit;
volatile Time t_current;
volatile unsigned int interval;
volatile unsigned int lastinterval;
/// void getBits(volatile unsigned char* target, const DCF start, const char len, const DCF parity);
/// void set_dcf_value();
void timer_init();
/// void interrupts_init();
#endif
|