Subversion Repositories idreammicro-avr

Rev

Rev 19 | Rev 42 | Go to most recent revision | Details | Compare with Previous | 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>
24 jlesech 39
#include <stdlib.h>
19 jlesech 40
#include <string.h>
41
 
42
/******************************************************************************
43
 * Main function.
44
 ******************************************************************************/
45
 
46
/**************************************************************************//**
47
 * \fn int main(void)
48
 *
49
 * \brief Main function.
50
 *
51
 * \return 0
52
 ******************************************************************************/
53
int main(void)
54
{
55
    // Initialize USART0.
56
    usart0__initialize(NULL);
57
 
58
    // Enbale transmitter.
59
    usart0__enable_transmitter();
60
 
61
    // Initialize RTC.
62
        ds1307__initialize();
63
 
64
        // Declare some variables.
65
        datetime__time_t time =
66
        {
67
                .seconds        = 00,
68
                .minutes        = 29,
69
                .hours          = 19,
70
                .meridiem       = 0
71
        };
72
        ds1307__hour_mode_t hour_mode = DS1307__HOUR_MODE__24_HOUR;
73
 
74
        datetime__date_t date =
75
        {
76
                .day    = 3,
77
                .date   = 5,
78
                .month  = 5,
79
                .year   = 9
80
        };
81
 
82
        // Set time and hour mode.
83
        //ds1307__set_time(&time, hour_mode);
84
 
85
        // Set date.
86
        //ds1307__set_date(&date);
87
 
24 jlesech 88
        for (;;)
19 jlesech 89
        {
90
                // Get RTC time.
91
                ds1307__get_time(&time, &hour_mode);
92
 
93
                // Get RTC date.
94
                ds1307__get_date(&date);
95
 
96
                char str_datetime[] = "dd/mm/yy hh:mm:ss\n";
97
 
98
                snprintf
99
                (
100
                        str_datetime,
101
                        strlen(str_datetime) + 1,
102
                        "%02u/%02u/%02u %02u:%02u:%02u\n",
103
                        date.date,
104
                        date.month,
105
                        date.year,
106
                        time.hours,
107
                        time.minutes,
108
                        time.seconds
109
                );
110
 
111
                char* p_str = str_datetime;
112
                while (*p_str != '\0')
113
                {
114
                        usart0__transmit_byte(*p_str);
115
                        p_str++;
116
                }
117
 
118
                _delay_ms(1000);
119
        }
120
 
121
        return 0;
122
}