📄 calender.lst
字号:
208 1 }
209 /*
210 *********************************************************************************************************
211 * FORMAT CURRENT DATE INTO STRING
212 *
213 * Description : Formats the current date into an ASCII string.
214 * Arguments : mode is the format type:
215 * 1 will format the time as "MM-DD-YY" (needs at least 9 characters)
216 * 2 will format the time as "Day Month DD, YYYY" (needs at least 30 characters)
217 * 3 will format the time as "YYYY-MM-DD" (needs at least 11 characters)
218 * s is a pointer to the destination string. The destination string must be large
219 * enough to hold the formatted date.
220 * contain
221 * Returns : None.
222 * Notes : - A 'switch' statement has been used to allow you to add your own date formats. For
223 * example, you could display the date in French, Spanish, German etc. by assigning
224 * numbers for those types of conversions.
225 * - This function assumes that strcpy(), strcat() and itoa() are reentrant.
226 *********************************************************************************************************
227 */
228 #if CLK_DATE_EN
229 void Clk_format_date (UCHAR mode, char *s)
230 {
231 1 UINT year;
232 1 char str[5];
233 1
234 1 switch (mode)
235 1 {
236 2 case 1:
C51 COMPILER V7.50 CALENDER 02/24/2006 20:38:40 PAGE 5
237 2 strcpy(s, "MM-DD-YY"); /* Create the template for the selected format */
238 2 s[0] = ClkMonth / 10 + '0'; /* Convert DATE to ASCII */
239 2 s[1] = ClkMonth % 10 + '0';
240 2 s[3] = ClkDay / 10 + '0';
241 2 s[4] = ClkDay % 10 + '0';
242 2 year = ClkYear % 100;
243 2 s[6] = year / 10 + '0';
244 2 s[7] = year % 10 + '0';
245 2 break;
246 2
247 2 case 2:
248 2 strcpy(s, ClkDOWTbl[ClkDOW]); /* Get the day of the week */
249 2 strcat(s, ClkMonthTbl[ClkMonth].MonthName); /* Get name of month */
250 2 if (ClkDay < 10)
251 2 {
252 3 str[0] = ClkDay + '0';
253 3 str[1] = 0;
254 3 }
255 2 else
256 2 {
257 3 str[0] = ClkDay / 10 + '0';
258 3 str[1] = ClkDay % 10 + '0';
259 3 str[2] = 0;
260 3 }
261 2 strcat(s, str);
262 2 strcat(s, ", ");
263 2 sprintf(str,"%d",ClkYear);
264 2 strcat(s, str);
265 2 break;
266 2
267 2 case 3:
268 2 strcpy(s, "YYYY-MM-DD"); /* Create the template for the selected format */
269 2 s[0] = year / 1000 + '0';
270 2 year = year % 1000;
271 2 s[1] = year / 100 + '0';
272 2 year = year % 100;
273 2 s[2] = year / 10 + '0';
274 2 s[3] = year % 10 + '0';
275 2 s[5] = ClkMonth / 10 + '0'; /* Convert DATE to ASCII */
276 2 s[6] = ClkMonth % 10 + '0';
277 2 s[8] = ClkDay / 10 + '0';
278 2 s[9] = ClkDay % 10 + '0';
279 2 break;
280 2
281 2 default:
282 2 strcpy(s, "?");
283 2 break;
284 2 }
285 1 }
286 #endif
287 /*
288 *********************************************************************************************************
289 * FORMAT CURRENT TIME INTO STRING
290 *
291 * Description : Formats the current time into an ASCII string.
292 * Arguments : mode is the format type:
293 * 1 will format the time as "HH:MM:SS" (24 Hour format)
294 * (needs at least 9 characters)
295 * 2 will format the time as "HH:MM:SS AM" (With AM/PM indication)
296 * (needs at least 13 characters)
297 * s is a pointer to the destination string. The destination string must be large
298 * enough to hold the formatted time.
C51 COMPILER V7.50 CALENDER 02/24/2006 20:38:40 PAGE 6
299 * contain
300 * Returns : None.
301 * Notes : - A 'switch' statement has been used to allow you to add your own time formats.
302 * - This function assumes that strcpy() is reentrant.
303 *********************************************************************************************************
304 */
305 void Clk_format_time (UCHAR mode, char *s)
306 {
307 1 UCHAR hr;
308 1 switch (mode)
309 1 {
310 2 case 1:
311 2 strcpy(s, "HH:MM:SS"); /* Create the template for the selected format */
312 2 s[0] = ClkHr / 10 + '0'; /* Convert TIME to ASCII */
313 2 s[1] = ClkHr % 10 + '0';
314 2 s[3] = ClkMin / 10 + '0';
315 2 s[4] = ClkMin % 10 + '0';
316 2 s[6] = ClkSec / 10 + '0';
317 2 s[7] = ClkSec % 10 + '0';
318 2 break;
319 2
320 2 case 2:
321 2 strcpy(s, "HH:MM:SS AM"); /* Create the template for the selected format */
322 2 s[9] = (ClkHr >= 12) ? 'P' : 'A'; /* Set AM or PM indicator */
323 2 if (ClkHr > 12)
324 2 { /* Adjust time to be displayed */
325 3 hr = ClkHr - 12;
326 3 }
327 2 else
328 2 {
329 3 hr = ClkHr;
330 3 }
331 2 s[0] = hr / 10 + '0'; /* Convert TIME to ASCII */
332 2 s[1] = hr % 10 + '0';
333 2 s[3] = ClkMin / 10 + '0';
334 2 s[4] = ClkMin % 10 + '0';
335 2 s[6] = ClkSec / 10 + '0';
336 2 s[7] = ClkSec % 10 + '0';
337 2 break;
338 2
339 2 default:
340 2 strcpy(s, "?");
341 2 break;
342 2 }
343 1 }
344 /*
345 *********************************************************************************************************
346 * UPDATE THE TIME
347 *
348 * Description : This function is called to update the time (i.e. hours, minutes and seconds)
349 * Arguments : None.
350 * Returns : TRUE if we have completed one day.
351 * FALSE otherwise
352 * Notes : This function updates ClkSec, ClkMin and ClkHr.
353 *********************************************************************************************************
354 */
355 static BOOL ClkUpdateTime (void)
356 {
357 1 BOOL newday;
358 1
359 1 newday = FALSE; /* Assume that we haven't completed one whole day yet *
-/
C51 COMPILER V7.50 CALENDER 02/24/2006 20:38:40 PAGE 7
360 1 if (ClkSec >= 59)
361 1 { /* See if we have completed one minute yet *
-/
362 2 ClkSec = 0; /* Yes, clear seconds *
-/
363 2 if (ClkMin >= 59)
364 2 { /* See if we have completed one hour yet *
-/
365 3 ClkMin = 0; /* Yes, clear minutes *
-/
366 3 if (ClkHr >= 23)
367 3 { /* See if we have completed one day yet *
-/
368 4 ClkHr = 0; /* Yes, clear hours ... *
-/
369 4 newday = TRUE; /* ... change flag to indicate we have a new day *
-/
370 4 }
371 3 else
372 3 {
373 4 ClkHr++; /* No, increment hours *
-/
374 4 }
375 3 }
376 2 else
377 2 {
378 3 ClkMin++; /* No, increment minutes *
-/
379 3 }
380 2 }
381 1 else
382 1 {
383 2 ClkSec++; /* No, increment seconds *
-/
384 2 }
385 1 return (newday);
386 1 }
387 /*
388 *********************************************************************************************************
389 * SET TIME ONLY
390 *
391 * Description : Set the time-of-day clock
392 * Arguments : hr is the desired hour (0..23)
393 * min is the desired minutes (0..59)
394 * sec is the desired seconds (0..59)
395 * Returns : None.
396 * Notes : It is assumed that you are specifying a correct time (i.e. there is no range checking
397 * done by this function).
398 *********************************************************************************************************
399 */
400 void Clk_set_time (UCHAR hr, UCHAR min, UCHAR sec)
401 {
402 1 ENTER_CRITICAL(); /* Gain exclusive access to time-of-day clock */
403 1 ClkHr = hr;
404 1 ClkMin = min;
405 1 ClkSec = sec;
406 1 EXIT_CRITICAL(); /* Release access to time-of-day clock */
407 1 }
408 /*
409 *********************************************************************************************************
410 * DETERMINE IF WE HAVE A LEAP YEAR
411 *
C51 COMPILER V7.50 CALENDER 02/24/2006 20:38:40 PAGE 8
412 * Description : This function determines whether the 'year' passed as an argument is a leap year.
413 * Arguments : year is the year to check for leap year.
414 * Returns : TRUE if 'year' is a leap year.
415 * FALSE if 'year' is NOT a leap year.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -