Rev 24 |
Rev 43 |
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 <deuligne/deuligne.h>
#include <ds1307/ds1307.h>
#include <twi/twi.h>
#include <usart/usart0.h>
#include <useful/datetime.h>
#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/******************************************************************************
* Main function.
******************************************************************************/
/**************************************************************************//**
* \fn int main(void)
*
* \brief Main function.
*
* \return 0
******************************************************************************/
int main
(void)
{
// Initialize USART0.
usart0__initialize
(NULL
);
// Enable transmitter.
usart0__enable_transmitter
();
// Initialize TWI.
twi__initialize
(100000);
// 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
};
// Initialize Deuligne and configure display.
deuligne__initialize
();
deuligne__set_display
(true, true, true);
// Switch on backlight.
deuligne__switch_on_backlight
();
// Set time and hour mode.
//ds1307__set_time(&time, hour_mode);
// Set date.
//ds1307__set_date(&date);
for (;;)
{
// Get RTC time.
ds1307__get_time
(&time, &hour_mode
);
// Get RTC date.
ds1307__get_date
(&date
);
char str_date
[] = "dd/mm/yy";
snprintf
(
str_date
,
strlen(str_date
) + 1,
"%02u/%02u/%02u",
date.
date,
date.
month,
date.
year
);
char str_time
[] = "hh:mm:ss";
snprintf
(
str_time
,
strlen(str_time
) + 1,
"%02u:%02u:%02u",
time.
hours,
time.
minutes,
time.
seconds
);
char* p_date
= &(str_date
[0]);
while(*p_date
!= '\0')
{
usart0__transmit_byte
(*p_date
);
p_date
++;
}
usart0__transmit_byte
(' ');
char* p_time
= &(str_time
[0]);
while(*p_time
!= '\0')
{
usart0__transmit_byte
(*p_time
);
p_time
++;
}
usart0__transmit_byte
('\n');
deuligne__set_cursor_position
(DEULIGNE__DISPLAY_LINE_1
, 0);
deuligne__write_string
(str_date
);
deuligne__set_cursor_position
(DEULIGNE__DISPLAY_LINE_2
, 0);
deuligne__write_string
(str_time
);
_delay_ms
(1000);
}
return 0;
}