summaryrefslogtreecommitdiff
path: root/clock.c
blob: e6fba14d317fda47aeb9c61fae1b53d9b1ff415a (plain)
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
/************************************************************************/
/*									*/
/*			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;
      }
    }
  }
}