1 /*-------------------------------------------------------------------------
2 rtc390.c - rtc demo for the DS1315 (tested on TINI)
4 Written By - Johan Knol, johan.knol@iduna.nl
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 In other words, you are welcome to use, share and improve this program.
21 You are forbidden to forbid anyone else to use, share and improve
22 what you give them. Help stamp out software-hoarding!
23 -------------------------------------------------------------------------*/
30 int ScanInt(int current) {
34 if (isdigit(*(r=reply))) {
39 } while (isdigit(*r));
44 char GetTime(struct RTCDate *rtcDate) {
45 printf ("Enter year [%d]: ", rtcDate->year);
46 rtcDate->year=ScanInt(rtcDate->year);
47 printf ("Enter month [%d]: ", rtcDate->month);
48 rtcDate->month=ScanInt(rtcDate->month);
49 printf ("Enter day [%d]: ", rtcDate->day);
50 rtcDate->day=ScanInt(rtcDate->day);
51 printf ("Enter hour [%d]: ", rtcDate->hour);
52 rtcDate->hour=ScanInt(rtcDate->hour);
53 printf ("Enter minute [%d]: ", rtcDate->minute);
54 rtcDate->minute=ScanInt(rtcDate->minute);
55 printf ("Enter second [%d]: ", rtcDate->second);
56 rtcDate->second=ScanInt(rtcDate->second);
60 void PrintTime(struct RTCDate *rtcDate) {
61 printf ("%04d-%02d-%02d %02d:%02d:%02d.%02d\n",
62 rtcDate->year, rtcDate->month, rtcDate->day,
63 rtcDate->hour, rtcDate->minute, rtcDate->second,
68 struct RTCDate rtcDate;
69 unsigned char seconds=0xff;
71 printf ("\nStarting RTC demo.\n");
75 LcdLPrintf (0, "Starting RTC demo.");
82 // if lcd is enabled it only syncs the second time
87 LcdLPrintf (2,"%04d-%02d-%02d",
88 rtcDate.year, rtcDate.month, rtcDate.day);
89 LcdLPrintf (3, "%02d:%02d:%02d.%02d",
90 rtcDate.hour, rtcDate.minute, rtcDate.second,
93 if (rtcDate.second!=seconds) {
95 seconds=rtcDate.second;
98 if (Serial0CharArrived()) {
107 if (GetTime(&rtcDate)) {
111 printf ("Time written.\n");