Subversion Repositories idreammicro-avr

Rev

Rev 37 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
19 jlesech 1
/**************************************************************************//**
2
 * \brief DS1307 RTC library - Demonstration program
3
 * \author Copyright (C) 2011  Julien Le Sech - www.idreammicro.com
4
 * \version 1.0
5
 * \date 20090501
6
 *
7
 * This file is part of the iDreamMicro library.
8
 *
9
 * This library is free software: you can redistribute it and/or modify it under
10
 * the terms of the GNU Lesser General Public License as published by the Free
11
 * Software Foundation, either version 3 of the License, or (at your option) any
12
 * later version.
13
 *
14
 * This library is distributed in the hope that it will be useful, but WITHOUT
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17
 * details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with this program. If not, see http://www.gnu.org/licenses/
21
 ******************************************************************************/
22
 
23
/**************************************************************************//**
24
 * \file demo_ds1307.c
25
 ******************************************************************************/
26
 
27
/******************************************************************************
28
 * Header file inclusions.
29
 ******************************************************************************/
30
 
31
#include <ds1307/ds1307.h>
32
#include <usart/usart0.h>
33
#include <useful/datetime.h>
34
 
35
#include <avr/io.h>
36
#include <util/delay.h>
37
 
38
#include <stdio.h>
39
#include <string.h>
40
 
41
/******************************************************************************
42
 * Main function.
43
 ******************************************************************************/
44
 
45
/**************************************************************************//**
46
 * \fn int main(void)
47
 *
48
 * \brief Main function.
49
 *
50
 * \return 0
51
 ******************************************************************************/
52
int main(void)
53
{
54
    // Initialize USART0.
55
    usart0__initialize(NULL);
56
 
57
    // Enbale transmitter.
58
    usart0__enable_transmitter();
59
 
60
    // Initialize RTC.
61
        ds1307__initialize();
62
 
63
        // Declare some variables.
64
        datetime__time_t time =
65
        {
66
                .seconds        = 00,
67
                .minutes        = 29,
68
                .hours          = 19,
69
                .meridiem       = 0
70
        };
71
        ds1307__hour_mode_t hour_mode = DS1307__HOUR_MODE__24_HOUR;
72
 
73
        datetime__date_t date =
74
        {
75
                .day    = 3,
76
                .date   = 5,
77
                .month  = 5,
78
                .year   = 9
79
        };
80
 
81
        // Set time and hour mode.
82
        //ds1307__set_time(&time, hour_mode);
83
 
84
        // Set date.
85
        //ds1307__set_date(&date);
86
 
87
        while (1)
88
        {
89
                // Get RTC time.
90
                ds1307__get_time(&time, &hour_mode);
91
 
92
                // Get RTC date.
93
                ds1307__get_date(&date);
94
 
95
                char str_datetime[] = "dd/mm/yy hh:mm:ss\n";
96
 
97
                snprintf
98
                (
99
                        str_datetime,
100
                        strlen(str_datetime) + 1,
101
                        "%02u/%02u/%02u %02u:%02u:%02u\n",
102
                        date.date,
103
                        date.month,
104
                        date.year,
105
                        time.hours,
106
                        time.minutes,
107
                        time.seconds
108
                );
109
 
110
                char* p_str = str_datetime;
111
                while (*p_str != '\0')
112
                {
113
                        usart0__transmit_byte(*p_str);
114
                        p_str++;
115
                }
116
 
117
                _delay_ms(1000);
118
        }
119
 
120
        return 0;
121
}