Subversion Repositories idreammicro-avr

Rev

Rev 37 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

/**************************************************************************//**
 * \brief DS1307 RTC library - Demonstration program
 * \author Copyright (C) 2011  Julien Le Sech - www.idreammicro.com
 * \version 1.0
 * \date 20090501
 *
 * This file is part of the iDreamMicro library.
 *
 * This library is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/
 ******************************************************************************/


/**************************************************************************//**
 * \file demo_ds1307.c
 ******************************************************************************/


/******************************************************************************
 * Header file inclusions.
 ******************************************************************************/


#include <ds1307/ds1307.h>
#include <usart/usart0.h>
#include <useful/datetime.h>

#include <avr/io.h>
#include <util/delay.h>

#include <stdio.h>
#include <string.h>

/******************************************************************************
 * Main function.
 ******************************************************************************/


/**************************************************************************//**
 * \fn int main(void)
 *
 * \brief Main function.
 *
 * \return 0
 ******************************************************************************/

int main(void)
{
    // Initialize USART0.
    usart0__initialize(NULL);

    // Enbale transmitter.
    usart0__enable_transmitter();

    // Initialize RTC.
        ds1307__initialize();

        // Declare some variables.
        datetime__time_t time =
        {
                .seconds        = 00,
                .minutes        = 29,
                .hours          = 19,
                .meridiem       = 0
        };
        ds1307__hour_mode_t hour_mode = DS1307__HOUR_MODE__24_HOUR;

        datetime__date_t date =
        {
                .day    = 3,
                .date   = 5,
                .month  = 5,
                .year   = 9
        };

        // Set time and hour mode.
        //ds1307__set_time(&time, hour_mode);

        // Set date.
        //ds1307__set_date(&date);

        while (1)
        {
                // Get RTC time.
                ds1307__get_time(&time, &hour_mode);

                // Get RTC date.
                ds1307__get_date(&date);

                char str_datetime[] = "dd/mm/yy hh:mm:ss\n";

                snprintf
                (
                        str_datetime,
                        strlen(str_datetime) + 1,
                        "%02u/%02u/%02u %02u:%02u:%02u\n",
                        date.date,
                        date.month,
                        date.year,
                        time.hours,
                        time.minutes,
                        time.seconds
                );

                char* p_str = str_datetime;
                while (*p_str != '\0')
                {
                        usart0__transmit_byte(*p_str);
                        p_str++;
                }

                _delay_ms(1000);
        }

        return 0;
}