📄 clock.lst
字号:
355 4 }
356 3 }
357 2 else
358 2 {
359 3 DisplayOneChar(10,1,0x20);
360 3 DisplayOneChar(11,1,0x20); //显示下限温度
361 3 DisplayOneChar(12,1,0x20);
362 3 }
363 2 }
364 1 else
365 1 {
C51 COMPILER V7.06 CLOCK 07/14/2008 21:00:26 PAGE 7
366 2 DisplayOneChar(10,1,th_bw+0x30);
367 2 DisplayOneChar(11,1,th_sw+0x30); //显示下限温度
368 2 DisplayOneChar(12,1,th_gw+0x30);
369 2 }
370 1 }
371
372 //设置温度下限
373 void Set_TL_Temp(void)
374 {
375 1 if(P0_5==0)
376 1 {
377 2 Delay5Ms();
378 2 if(P0_5==0)
379 2 {
380 3 tl++;
381 3 if(tl>125) tl=-55;
382 3 //if(tl<-55) tl=155;
383 3 }
384 2 while(P0_5==0);
385 2 }
386 1 if(P0_4==0)
387 1 {
388 2 Delay5Ms();
389 2 if(P0_4==0)
390 2 {
391 3 tl--;
392 3 if(tl<-55) tl=125;
393 3 }
394 2 }
395 1 }
396
397 //设置温度上限
398 void Set_TH_Temp(void)
399 {
400 1 if(P0_5==0)
401 1 {
402 2 Delay5Ms();
403 2 if(P0_5==0)
404 2 {
405 3 th++;
406 3 if(th>125) th=-55;
407 3 //if(tl<-55) tl=155;
408 3 }
409 2 while(P0_5==0);
410 2 }
411 1 if(P0_4==0)
412 1 {
413 2 Delay5Ms();
414 2 if(P0_4==0)
415 2 {
416 3 th--;
417 3 if(th<-55) th=125;
418 3 }
419 2 }
420 1 }
421
422 void Compare_Temp(signed char l,signed char h) //比较温度
423 {
424 1 unsigned char tl_temp;
425 1 unsigned char y,s;
426 1 //unsigned int x;
427 1 //unsigned char ct[8];
C51 COMPILER V7.06 CLOCK 07/14/2008 21:00:26 PAGE 8
428 1 union{byte c[2]; int x;}temp;
429 1
430 1 ow_reset();
431 1 write_byte(0xCC); // Skip ROM
432 1 write_byte(0x44); // 转换温度
433 1 ow_reset();
434 1 write_byte(0xCC); //Skip ROM
435 1 write_byte(0xbe); // 读取寄存器
436 1 temp.c[1]=read_byte();//读出温度低8位
437 1 temp.c[0]=read_byte();//读出温度高8位
438 1
439 1 // 零下温度判断
440 1 sflag=0; //温度零下标志 0:零上,1:零下
441 1 if((temp.c[0]&0xf8)!=0x00)
442 1 {
443 2 sflag=1; //零下标志位置1
444 2 temp.c[1]=~temp.c[1]; //低8位取反
445 2 temp.c[0]=~temp.c[0]; //高8位取反
446 2 tl_temp=temp.c[1]+1; //低8位加1
447 2 temp.c[1]=tl_temp; //计算后重新存入数组
448 2 if(tl_temp>255) temp.c[0]++; //如果低8位大于255,向高8位进1
449 2 }
450 1 y=0;
451 1 s=0;
452 1 y=temp.c[0]<<4;
453 1 s=temp.c[1]>>4;
454 1 y=s|y;
455 1 //x=((temp.c[0]&0x07)*256+temp.c[1])*.625;
456 1 if(y<l)
457 1
458 1 tl_flag=1;
459 1
460 1 else
461 1
462 1 tl_flag=0;
463 1
464 1 if(y>h)
465 1
466 1 th_flag=1;
467 1
468 1 else
469 1
470 1 th_flag=0;
471 1
472 1 }
473
474 void Tl_Al(void) //下限越限报?
475 {
476 1 if(tl_flag==1)
477 1 {
478 2 if(flag==1)
479 2 {
480 3 DisplayOneChar(9,0,'A');
481 3 DisplayOneChar(10,0,'L');
482 3 }
483 2 else
484 2 {
485 3 DisplayOneChar(9,0,0x20);
486 3 DisplayOneChar(10,0,0x20);
487 3 }
488 2 }
489 1 else
C51 COMPILER V7.06 CLOCK 07/14/2008 21:00:26 PAGE 9
490 1 {
491 2 DisplayOneChar(9,0,0x20);
492 2 DisplayOneChar(10,0,0x20);
493 2 }
494 1 }
495
496 void Th_Al(void) //上限越限报警
497 {
498 1 if(th_flag==1)
499 1 {
500 2 if(flag==1)
501 2 {
502 3 DisplayOneChar(13,0,'A');
503 3 DisplayOneChar(14,0,'H');
504 3 }
505 2 else
506 2 {
507 3 DisplayOneChar(13,0,0x20);
508 3 DisplayOneChar(14,0,0x20);
509 3 }
510 2 }
511 1 else
512 1 {
513 2 DisplayOneChar(13,0,0x20);
514 2 DisplayOneChar(14,0,0x20);
515 2 }
516 1 }
517
518
519
520 //中断入口,冒号闪烁
521 void t0(void) interrupt 1 using 0
522 {
523 1 TH0=(65535-50000)/256; //50ms定时
524 1 TL0=(65535-50000)%256;
525 1 timecount++;
526 1 if(timecount>9)
527 1 {
528 2 timecount=0;
529 2 flag=~flag;
530 2 }
531 1 }
532 //id为1时的下一级选择
533 void id_case1_key()
534 {
535 1 if (P0_5==0) //增加
536 1 {
537 2 Delay5Ms();
538 2 if(P0_5==0) Set(id,0);
539 2 if(id!=7) while(P0_5==0);
540 2 }
541 1 if (P0_4==0) //减少
542 1 {
543 2 Delay5Ms();
544 2 if(P0_4==0) Set(id,1);
545 2 if(id!=7) while(P0_4==0);
546 2 }
547 1 }
548
549 //根据选择调整相应项目并写入DS1302
550 void Set(uchar sel,uchar sel_1)
551 {
C51 COMPILER V7.06 CLOCK 07/14/2008 21:00:26 PAGE 10
552 1 signed char address,item;
553 1 signed char max,mini;
554 1 if(sel==7) {address=0x80; max=0;mini=0;} //秒
555 1 if(sel==6) {address=0x82; max=59;mini=0;} //分钟
556 1 if(sel==5) {address=0x84; max=23;mini=0;} //小时
557 1 if(sel==3) {address=0x86; max=31;mini=1;} //日
558 1 if(sel==2) {address=0x88; max=12;mini=1;} //月
559 1 if(sel==1) {address=0x8c; max=99;mini=0;} //年
560 1 if(sel==4) {address=0x8a; max=7; mini=1;} //星期
561 1
562 1 item=R1302(address+1)/16*10+R1302(address+1)%16;
563 1 if (sel_1==0) item++; else item--;
564 1 if(item>max) item=mini;
565 1 if(item<mini) item=max;
566 1
567 1 W1302(0x8e,0x00);//允许写操作
568 1 W1302(address,item/10*16+item%10);
569 1 W1302(0x8e,0x80);//写保护,禁止写操作
570 1 }
571
572 //屏幕显示第一行 时间和温度
573 void Disp_line1(void)
574 {
575 1 Read_Temperature(10,0); //温度显示
576 1 //冒号闪烁
577 1 if(flag==0)
578 1 {DisplayOneChar(3,0,0x3a); DisplayOneChar(6,0,0x3a);}
579 1 else
580 1 {DisplayOneChar(3,0,0x20); DisplayOneChar(6,0,0x20);}
581 1
582 1 if(sec==1) //秒闪烁标志位
583 1 {
584 2 if(flag==1)
585 2 {
586 3 DisplayOneChar(7,0,R1302(0x81)/16+0x30); //显示秒
587 3 DisplayOneChar(8,0,R1302(0x81)%16+0x30);
588 3 }
589 2 else
590 2 {
591 3 DisplayOneChar(7,0,0x20); //显示秒
592 3 DisplayOneChar(8,0,0x20);
593 3 }
594 2 }
595 1 else
596 1 {
597 2 DisplayOneChar(7,0,R1302(0x81)/16+0x30); //显示秒
598 2 DisplayOneChar(8,0,R1302(0x81)%16+0x30);
599 2 }
600 1
601 1 if(min==1) //分钟闪烁标志位
602 1 {
603 2 if(flag==1)
604 2 {
605 3 DisplayOneChar(4,0,R1302(0x83)/16+0x30); //显示分钟
606 3 DisplayOneChar(5,0,R1302(0x83)%16+0x30);
607 3 }
608 2 else
609 2 {
610 3 DisplayOneChar(4,0,0x20); //显示分钟
611 3 DisplayOneChar(5,0,0x20);
612 3 }
613 2 }
C51 COMPILER V7.06 CLOCK 07/14/2008 21:00:26 PAGE 11
614 1 else
615 1 {
616 2 DisplayOneChar(4,0,R1302(0x83)/16+0x30); //显示分钟
617 2 DisplayOneChar(5,0,R1302(0x83)%16+0x30);
618 2 }
619 1
620 1 if(hour==1) //小时闪烁标志位
621 1 {
622 2 if(flag==1)
623 2 {
624 3 DisplayOneChar(1,0,R1302(0x85)/16+0x30);//显示小时
625 3 DisplayOneChar(2,0,R1302(0x85)%16+0x30);
626 3 }
627 2 else
628 2 {
629 3 DisplayOneChar(1,0,0x20); //显示小时
630 3 DisplayOneChar(2,0,0x20);
631 3 }
632 2 }
633 1 else
634 1 {
635 2 DisplayOneChar(1,0,R1302(0x85)/16+0x30);//显示小时
636 2 DisplayOneChar(2,0,R1302(0x85)%16+0x30);
637 2 }
638 1 }
639
640 // 屏幕显示第二行 日期和星期
641 void Disp_line2(void)
642 {
643 1 DisplayOneChar(3,1,0x2f); //显示固定字符
644 1 DisplayOneChar(6,1,0x2f);
645 1 DisplayListChar(10,1,week);
646 1
647 1 if(year==1) //年闪烁标志位
648 1 {
649 2 if(flag==1)
650 2 {
651 3 DisplayOneChar(1,1,R1302(0x8d)/16+0x30);//显示年
652 3 DisplayOneChar(2,1,R1302(0x8d)%16+0x30);
653 3 }
654 2 else
655 2 {
656 3 DisplayOneChar(1,1,0x20); //显示年
657 3 DisplayOneChar(2,1,0x20);
658 3 }
659 2 }
660 1 else
661 1 {
662 2 DisplayOneChar(1,1,R1302(0x8d)/16+0x30);//显示年
663 2 DisplayOneChar(2,1,R1302(0x8d)%16+0x30);
664 2 }
665 1
666 1 if(mon==1) //月闪烁标志位
667 1 {
668 2 if(flag==1)
669 2 {
670 3 DisplayOneChar(4,1,R1302(0x89)/16+0x30);//显示月
671 3 DisplayOneChar(5,1,R1302(0x89)%16+0x30);
672 3 }
673 2 else
674 2 {
675 3 DisplayOneChar(4,1,0x20); //显示月
C51 COMPILER V7.06 CLOCK 07/14/2008 21:00:26 PAGE 12
676 3 DisplayOneChar(5,1,0x20);
677 3 }
678 2 }
679 1 else
680 1 {
681 2 DisplayOneChar(4,1,R1302(0x89)/16+0x30);//显示月
682 2 DisplayOneChar(5,1,R1302(0x89)%16+0x30);
683 2 }
684 1
685 1 if(day==1) //日闪烁标志位
686 1 {
687 2 if(flag==1)
688 2 {
689 3 DisplayOneChar(7,1,R1302(0x87)/16+0x30);//显示日
690 3 DisplayOneChar(8,1,R1302(0x87)%16+0x30);
691 3 }
692 2 else
693 2 {
694 3 DisplayOneChar(7,1,0x20); //显示日
695 3 DisplayOneChar(8,1,0x20);
696 3 }
697 2 }
698 1 else
699 1 {
700 2 DisplayOneChar(7,1,R1302(0x87)/16+0x30);//显示日
701 2 DisplayOneChar(8,1,R1302(0x87)%16+0x30);
702 2 }
703 1
704 1 if(weekk==1) //星期闪烁标志位
705 1 {
706 2 if(flag==1)
707 2 {
708 3 DisplayOneChar(15,1,R1302(0x8b)%16+0x30);//显示星期
709 3 }
710 2 else
711 2 {
712 3 DisplayOneChar(15,1,0x20); //显示星期
713 3 }
714 2 }
715 1 else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -