summaryrefslogtreecommitdiff
path: root/clock.c
diff options
context:
space:
mode:
Diffstat (limited to 'clock.c')
-rw-r--r--clock.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/clock.c b/clock.c
new file mode 100644
index 0000000..e6fba14
--- /dev/null
+++ b/clock.c
@@ -0,0 +1,88 @@
+/************************************************************************/
+/* */
+/* Clock / Calendar */
+/* */
+/* Author: Peter Dannegger */
+/* danni@specs.de */
+/* */
+/************************************************************************/
+
+#include "main.h"
+#include "clock.h"
+#include "max7219.h"
+#include "timebase.h"
+#include "dcf77.h"
+
+struct time data time;
+
+
+void display_date( void )
+{
+ displaymem[7] = time.day / 10;
+ displaymem[6] = time.day % 10 | ATTRIB_DP;
+ displaymem[5] = time.month / 10;
+ displaymem[4] = time.month % 10 | ATTRIB_DP;
+ displaymem[3] = 2;
+ displaymem[2] = 0;
+ displaymem[1] = time.year / 10;
+ displaymem[0] = time.year % 10;
+}
+
+
+void display_time(void)
+{
+ displaymem[7] = time.hour / 10;
+ displaymem[6] = time.hour % 10;
+
+ displaymem[4] = time.minute / 10;
+ displaymem[3] = time.minute % 10;
+
+ displaymem[1] = time.second / 10;
+ displaymem[0] = time.second % 10;
+}
+
+
+u8 code MDAYS[] = {
+ 29, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+
+
+void clock(void)
+{
+ u8 i;
+
+ time.second++;
+ if( time.second == 60 ){
+ time.second = 0;
+ timeflags = 1<<ONE_MINUTE; // to correct deviation per minute
+ time.minute++;
+ if( time.minute == 60 ){
+ time.minute = 0;
+ time.hour++;
+ switch( time.hour ){
+ case 24:
+ time.hour = 0;
+ time.day++;
+ time.wday++;
+ if( time.wday == 8 )
+ time.wday = 1;
+ i = time.month;
+ if( i == 2 && (time.year & 3) == 0 ) // leap year
+ i = 0;
+ if( LPM(MDAYS+1) == time.day ){
+ time.day = 1;
+ time.month++;
+ if( time.month == 13 ){
+ time.month = 1;
+ time.year++;
+ if( time.year == 100 )
+ time.year = 0; // next century
+ }
+ }
+ break;
+// case 2:
+// case 3: summertime(); break;
+ }
+ }
+ }
+}
+