Rev 36 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 18 | jlesech | 1 | /**************************************************************************//** |
| 2 | * \brief DS1307 RTC library - Demonstration program |
||
| 58 | jlesech | 3 | * \author Copyright (C) 2009 Julien Le Sech - www.idreammicro.com |
| 18 | jlesech | 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 | /**************************************************************************//** |
||
| 58 | jlesech | 24 | * \file ds1307__demo.c |
| 18 | jlesech | 25 | ******************************************************************************/ |
| 26 | |||
| 27 | /****************************************************************************** |
||
| 28 | * Header file inclusions. |
||
| 29 | ******************************************************************************/ |
||
| 30 | |||
| 31 | #include "../ds1307.h" |
||
| 32 | |||
| 36 | jlesech | 33 | #include <twi/twi.h> |
| 18 | jlesech | 34 | #include <useful/datetime.h> |
| 35 | |||
| 36 | #include <util/delay.h> |
||
| 37 | |||
| 38 | #include <stdio.h> |
||
| 39 | |||
| 40 | /****************************************************************************** |
||
| 41 | * Main function. |
||
| 42 | ******************************************************************************/ |
||
| 43 | |||
| 44 | /**************************************************************************//** |
||
| 45 | * \fn int main(void) |
||
| 46 | * |
||
| 47 | * \brief Main function. |
||
| 48 | * |
||
| 49 | * \return 0 |
||
| 50 | ******************************************************************************/ |
||
| 51 | int main(void) |
||
| 52 | { |
||
| 36 | jlesech | 53 | // Initialize TWI. |
| 54 | twi__initialize(DS1307__CLOCK_RATE); |
||
| 55 | |||
| 18 | jlesech | 56 | // Initialize RTC. |
| 57 | ds1307__initialize(); |
||
| 58 | |||
| 59 | // Declare some variables. |
||
| 60 | datetime__time_t time = |
||
| 61 | { |
||
| 62 | .seconds = 00, |
||
| 63 | .minutes = 29, |
||
| 64 | .hours = 19, |
||
| 65 | .meridiem = 0 |
||
| 66 | }; |
||
| 67 | ds1307__hour_mode_t hour_mode = DS1307__HOUR_MODE__24_HOUR; |
||
| 68 | |||
| 69 | datetime__date_t date = |
||
| 70 | { |
||
| 71 | .day = 3, |
||
| 72 | .date = 5, |
||
| 73 | .month = 5, |
||
| 74 | .year = 9 |
||
| 75 | }; |
||
| 76 | |||
| 77 | // Set time and hour mode. |
||
| 78 | ds1307__set_time(&time, hour_mode); |
||
| 79 | |||
| 80 | // Set date. |
||
| 81 | ds1307__set_date(&date); |
||
| 82 | |||
| 24 | jlesech | 83 | for (;;) |
| 18 | jlesech | 84 | { |
| 85 | // Get RTC time. |
||
| 86 | ds1307__get_time(&time, &hour_mode); |
||
| 87 | |||
| 88 | // Get RTC date. |
||
| 89 | ds1307__get_date(&date); |
||
| 90 | |||
| 91 | _delay_ms(100); |
||
| 92 | } |
||
| 93 | |||
| 94 | return 0; |
||
| 95 | } |