Hardware Reference
In-Depth Information
125 t1.tm_sec = v;
126 }
127
128 /
129
Check the validity of the date :
130
/
131 t1.tm_isdst = −1; /
Determine if daylight savings
/
132 t0 = t1; /
Save initial values
/
133 if ( mktime(&t1) == 1L ) { /
/
134 bad_date : printf("Argument '%s ' is not avalid calendar date.\
n",argv[1]) ;
135 exit(2);
136 }
137
138 /
t1 is modified
139
If struct t1 was adjusted , then the original date/time
140
values were invalid :
141
/
142 if ( t0.tm_year != t1.tm_year || t0.tm_mon != t1.tm_mon
143 || t0.tm_mday != t1.tm_mday || t0.tm_hour != t1.tm_hour
144 || t0.tm_min != t1.tm_min || t0.tm_sec != t1.tm_sec )
145 goto bad_date;
146
147 /
148
Populate DS1307 registers :
149
/
150 rtc.secs_10s = t1.tm_sec / 10;
151 rtc.secs_1s = t1.tm_sec % 10;
152 rtc.mins_10s = t1.tm_min / 10;
153 rtc.mins_1s = t1.tm_min % 10;
154 rtc.hour_10s = t1.tm_hour / 10;
155 rtc.hour_1s = t1.tm_hour % 10;
156 rtc.month_10s = (t1.tm_mon + 1) / 10;
157 rtc.month_1s = (t1.tm_mon + 1) % 10;
158 rtc.day_10s = t1.tm_mday / 10;
159 rtc.day_1s = t1.tm_mday % 10;
160 rtc.year_10s = (t1.tm_year + 1900 − 2000) / 10;
161 rtc.year_1s = (t1.tm_year + 1900 − 2000) % 10;
162
163 rtc.wkday = t1.tm_wday + 1; /
Weekday 1−7
/
164 rtc.mode_1224 = 0; /
Use 24 hour format
/
165
166 #if 0 /
/
167 printf("%d%d−%d%d−%d%d %d%d:%d%d:%d%d (wkday %d )\n",
168 rtc.year_10s,rtc.year_1s,
169 rtc.month_10s,rtc.month_1s,
170 rtc.day_10s,rtc.day_1s,
Change to a 1 for debugging
Search WWH ::




Custom Search