📄 mylcd.lst
字号:
279 4 day_temp=day_num[day_now.month-1];
280 4 day_now.year++;
281 4 leap=leapf(day_now.year);
282 4 }
283 3 }
284 2 }
285 1 }
286
287
288
289
290 /****************************************************************
291 **begin()子函数系统参数初始化
292 **
293 ****************************************************************/
294 void begin(){
295 1 //定时器0初始化
296 1 TMOD=0x21; //50ms int 12M
297 1 TH0=0x3c;
298 1 TL0=0xba;
299 1 TR0=1;
300 1 IE=0x92;
301 1 SCON|=0x40;
302 1 //状态标志位初始化
303 1
C51 COMPILER V7.50 MYLCD 05/12/2005 10:41:59 PAGE 6
304 1 //参量初始化
305 1 time_now.second=0;
306 1 time_now.minute=0;
307 1 time_now.hour=0;
308 1
309 1 day_now.year=1980;
310 1 day_now.month=6;
311 1 day_now.day=27;
312 1 leap=leapf(day_now.year);
313 1 day_temp=day_num[day_now.month-1];
314 1 }
315
316
317
318 /****************************************************************
319 **display()子函数
320 **参数说明:*cpoint:要显示的字符地址指针
321 ** x_line:横轴坐标(1-16)
322 ** y_line:纵轴坐标(1-16)
323 ** s_l: 1为8*16字体;2为16*16字体
324 **返回值:无
325 ****************************************************************/
326 void display(unsigned char *cpoint,unsigned char x_line,unsigned char y_line,unsigned char s_l){
327 1 unsigned char xdata *xpoint;
328 1 unsigned char i,j;
329 1 xpoint=0x8000+x_line+y_line*16;
330 1 for(i=0;i<16;i++){
331 2 for(j=0;j<s_l;j++){
332 3 *xpoint=*cpoint;
333 3 cpoint++;
334 3 xpoint++;
335 3 }
336 2 xpoint=xpoint+16-s_l;
337 2 }
338 1
339 1 }
340
341
342 /****************************************************************
343 **display_begin()子函数显示屏幕的初始值如:
344 ** —————————
345 ** | 1980年09月05日|
346 ** | 23时03分09秒|
347 ** —————————
348 **调用函数:display()
349 ** display_time()
350 **
351 ****************************************************************/
352 //指定位置显示“年,月,日,时,分,秒”
353 //unsigned char code zhi_loc[]=
354 //{0x06,0x01,0x0a,0x01,0x0e,0x01,0x06,0x10,0x0a,0x10,0x0e,0x10};
355 void display_begin(){
356 1 unsigned char x_display,y_display,i,j=0;
357 1 unsigned char code *p_display;
358 1 p_display=&shi;
359 1
360 1 for (i=0;i<6;i++){
361 2 x_display=zhi_loc[j];
362 2 j++;
363 2 y_display=zhi_loc[j];
364 2 j++;
365 2 display(p_display,x_display,y_display,2);
C51 COMPILER V7.50 MYLCD 05/12/2005 10:41:59 PAGE 7
366 2 p_display=p_display+32;
367 2 }
368 1
369 1 //指定位置显示时间
370 1 display_time(time_now,day_now);
371 1
372 1 }
373
374 /****************************************************************
375 ** display_time()显示时间子函数
376 ** 参数:struct time_str time
377 ** struct day_str day
378 ** 返回值:无
379 ** 调用函数:display()
380 ** hex_bcd()
381 ****************************************************************/
382 void display_time(struct time_str time,struct day_str day){
383 1 unsigned char temp,temp1,temp_year,temp_x,temp_y;
384 1 unsigned char *temp_p;
385 1
386 1
387 1 //显示哭笑符
388 1 if (ku_flag)temp_p=(&ku)+32;
389 1 else temp_p=&ku;
390 1 temp_x=0;
391 1 temp_y=16;
392 1 ku_flag=!ku_flag;
393 1 display(temp_p,temp_x,temp_y,2);
394 1
395 1 //显示秒
396 1 temp=time.second;
397 1 temp=hex_bcd(temp);
398 1 temp1=temp>>4;
399 1 temp=temp&0xf;
400 1 temp_p=(&num)+16*temp;
401 1 temp_x=13;
402 1 temp_y=16;
403 1 display(temp_p,temp_x,temp_y,1);
404 1 temp_x=12;
405 1 temp_p=(&num)+16*temp1;
406 1 display(temp_p,temp_x,temp_y,1);
407 1
408 1 //显示分
409 1 temp=time.minute;
410 1 temp=hex_bcd(temp);
411 1 temp1=temp>>4;
412 1 temp=temp&0xf;
413 1 temp_p=(&num)+16*temp;
414 1 temp_x=9;
415 1 temp_y=16;
416 1 display(temp_p,temp_x,temp_y,1);
417 1 temp_x=8;
418 1 temp_p=(&num)+16*temp1;
419 1 display(temp_p,temp_x,temp_y,1);
420 1
421 1 //显示时
422 1 temp=time.hour;
423 1 temp=hex_bcd(temp);
424 1 temp1=temp>>4;
425 1 temp=temp&0xf;
426 1 temp_p=(&num)+16*temp;
427 1 temp_x=5;
C51 COMPILER V7.50 MYLCD 05/12/2005 10:41:59 PAGE 8
428 1 temp_y=16;
429 1 display(temp_p,temp_x,temp_y,1);
430 1 temp_x=4;
431 1 temp_p=(&num)+16*temp1;
432 1 display(temp_p,temp_x,temp_y,1);
433 1
434 1 //显示日
435 1 temp=day.day;
436 1 temp=hex_bcd(temp);
437 1 temp1=temp>>4;
438 1 temp=temp&0xf;
439 1 temp_p=(&num)+16*temp;
440 1 temp_x=13;
441 1 temp_y=0;
442 1 display(temp_p,temp_x,temp_y,1);
443 1 temp_x=12;
444 1 temp_p=(&num)+16*temp1;
445 1 display(temp_p,temp_x,temp_y,1);
446 1
447 1 //显示月
448 1 temp=day.month;
449 1 temp=hex_bcd(temp);
450 1 temp1=temp>>4;
451 1 temp=temp&0xf;
452 1 temp_p=(&num)+16*temp;
453 1 temp_x=9;
454 1 temp_y=0;
455 1 display(temp_p,temp_x,temp_y,1);
456 1 temp_x=8;
457 1 temp_p=(&num)+16*temp1;
458 1 display(temp_p,temp_x,temp_y,1);
459 1
460 1
461 1 //显示年
462 1 temp_year=day.year/100;
463 1 temp=day.year%100;
464 1 temp=hex_bcd(temp);
465 1 temp1=temp>>4;
466 1 temp=temp&0xf;
467 1 temp_p=(&num)+16*temp;
468 1 temp_x=5;
469 1 temp_y=0;
470 1 display(temp_p,temp_x,temp_y,1);
471 1 temp_x=4;
472 1 temp_p=(&num)+16*temp1;
473 1 display(temp_p,temp_x,temp_y,1);
474 1
475 1 //显示年高位
476 1 temp=hex_bcd(temp_year);
477 1 temp1=temp>>4;
478 1 temp=temp&0xf;
479 1 temp_p=(&num)+16*temp;
480 1 temp_x=3;
481 1 temp_y=0;
482 1 display(temp_p,temp_x,temp_y,1);
483 1 temp_x=2;
484 1 temp_p=(&num)+16*temp1;
485 1 display(temp_p,temp_x,temp_y,1);
486 1
487 1 }
488
489 /****************************************************************
C51 COMPILER V7.50 MYLCD 05/12/2005 10:41:59 PAGE 9
490 **润年判断leap()子函数
491 **参数:unsigned int year
492 **返回字:润年标志leap0为非润年
493 **内部变量:bit leap1
494 ****************************************************************/
495 bit leapf(unsigned int year){
496 1 bit bdata leap1;
497 1 if(year%4==0){
498 2 if(year%100==0){
499 3 if(year%400==0){
500 4 leap1=1;
501 4 }
502 3 else leap1=0;
503 3 }
504 2 else leap1=1;
505 2 }
506 1 else leap1=0;
507 1 return(leap1);
508 1 }
509 /****************************************************************
510 **hex_bcd()子函数
511 **参数:hex需要转换的单字节16进制数
512 **返回字:转换完成的单字节bcd码,高4位为高位低4位为低位
513 **内部变量:bcd,temp为无符号字符型
514 ****************************************************************/
515 unsigned char hex_bcd(unsigned char hex){
516 1 unsigned char bcd,temp;
517 1
518 1 bcd=hex%10;
519 1 temp=hex/10;
520 1 temp=temp<<4;
521 1 bcd=bcd|temp;
522 1 return (bcd);
523 1 }
524
525 /****************************************************************
526 ** key()键盘子函数
527 ** 键盘为两键式一个键
528 ** 参数:
529 ****************************************************************/
530
531
532
533 /****************************************************************
534 ** time0()定时器0中断子函数,产生50ms中断
535 **
536 ****************************************************************/
537 void time0() interrupt 1 using 1{
538 1 TH0=0x3c; //time0 50ms interrupt
539 1 TL0=0xba;
540 1 TR0=1;
541 1 msecond++;
542 1 if (msecond==20){
543 2 second_flag=1;
544 2 msecond=0;
545 2 }
546 1 }
547
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 997 ----
C51 COMPILER V7.50 MYLCD 05/12/2005 10:41:59 PAGE 10
CONSTANT SIZE = 628 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 22 27
IDATA SIZE = ---- ----
BIT SIZE = 5 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -