Subversion Repositories idreammicro-avr

Rev

Rev 24 | 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
 
37 jlesech 31
#include <deuligne/deuligne.h>
19 jlesech 32
#include <ds1307/ds1307.h>
37 jlesech 33
#include <twi/twi.h>
19 jlesech 34
#include <usart/usart0.h>
35
#include <useful/datetime.h>
36
 
37
#include <avr/io.h>
38
#include <util/delay.h>
39
 
40
#include <stdio.h>
24 jlesech 41
#include <stdlib.h>
19 jlesech 42
#include <string.h>
43
 
44
/******************************************************************************
45
 * Main function.
46
 ******************************************************************************/
47
 
48
/**************************************************************************//**
49
 * \fn int main(void)
50
 *
51
 * \brief Main function.
52
 *
53
 * \return 0
54
 ******************************************************************************/
55
int main(void)
56
{
57
    // Initialize USART0.
58
    usart0__initialize(NULL);
59
 
37 jlesech 60
    // Enable transmitter.
19 jlesech 61
    usart0__enable_transmitter();
62
 
37 jlesech 63
    // Initialize TWI.
64
    twi__initialize(100000);
65
 
19 jlesech 66
    // Initialize RTC.
67
        ds1307__initialize();
68
 
69
        // Declare some variables.
70
        datetime__time_t time =
71
        {
72
                .seconds        = 00,
73
                .minutes        = 29,
74
                .hours          = 19,
75
                .meridiem       = 0
76
        };
77
        ds1307__hour_mode_t hour_mode = DS1307__HOUR_MODE__24_HOUR;
78
 
79
        datetime__date_t date =
80
        {
81
                .day    = 3,
82
                .date   = 5,
83
                .month  = 5,
84
                .year   = 9
85
        };
86
 
37 jlesech 87
        // Initialize Deuligne and configure display.
88
    deuligne__initialize();
89
    deuligne__set_display(true, true, true);
90
 
91
    // Switch on backlight.
92
    deuligne__switch_on_backlight();
93
 
19 jlesech 94
        // Set time and hour mode.
95
        //ds1307__set_time(&time, hour_mode);
96
 
97
        // Set date.
98
        //ds1307__set_date(&date);
99
 
24 jlesech 100
        for (;;)
19 jlesech 101
        {
102
                // Get RTC time.
103
                ds1307__get_time(&time, &hour_mode);
104
 
105
                // Get RTC date.
106
                ds1307__get_date(&date);
107
 
37 jlesech 108
                char str_date[] = "dd/mm/yy";
109
        snprintf
110
        (
111
            str_date,
112
            strlen(str_date) + 1,
113
            "%02u/%02u/%02u",
114
            date.date,
115
            date.month,
116
            date.year
117
        );
19 jlesech 118
 
37 jlesech 119
        char str_time[] = "hh:mm:ss";
120
        snprintf
121
        (
122
            str_time,
123
            strlen(str_time) + 1,
124
            "%02u:%02u:%02u",
125
            time.hours,
126
            time.minutes,
127
            time.seconds
128
        );
19 jlesech 129
 
37 jlesech 130
        char* p_date = &(str_date[0]);
131
        while(*p_date != '\0')
132
        {
133
            usart0__transmit_byte(*p_date);
134
            p_date++;
135
        }
136
        usart0__transmit_byte(' ');
19 jlesech 137
 
37 jlesech 138
        char* p_time = &(str_time[0]);
139
        while(*p_time != '\0')
140
        {
141
            usart0__transmit_byte(*p_time);
142
            p_time++;
143
        }
144
        usart0__transmit_byte('\n');
145
 
146
        deuligne__set_cursor_position(DEULIGNE__DISPLAY_LINE_1, 0);
147
        deuligne__write_string(str_date);
148
 
149
        deuligne__set_cursor_position(DEULIGNE__DISPLAY_LINE_2, 0);
150
        deuligne__write_string(str_time);
151
 
19 jlesech 152
                _delay_ms(1000);
153
        }
154
 
155
        return 0;
156
}