📄 spy_lcd.lst
字号:
469 /*从下到上,从左到右进行刷新*/
470
471 void draw_srec(point p1,point p2,uchar s)
472 {
473 1 uchar a,i,j,min,max;
474 1 if(p1.x>p2.x) {a=p1.x;p1.x=p2.x;p2.x=a;}
475 1 if(p1.y>p2.y) {a=p1.y;p1.y=p2.y;p2.y=a;}
476 1 if((p1.x<128)&(p1.y<64))
477 1 {
478 2 if(p2.x>127) p2.x=127;
479 2 if(p2.y>63) p2.y=63;
480 2 min=MIN(p1.y/8,p2.y/8);
481 2 max=MAX(p1.y/8,p2.y/8);
482 2 for(i=max+1;i>=min+1;i--)
483 2 {
484 3
485 3 for(j=p1.x;j<=p2.x;j++)
486 3 {
487 4 if(j<=63)
488 4 {
489 5 iwl(0xb8|(i-1));//page
490 5 iwl(0x40|j);
491 5 a=drl();
492 5 a=drl();
493 5 iwl(0x40|j);
494 5 if(min!=max)
495 5 {
496 6 if(i==min+1)//最上边一页的处理
497 6 {
498 7 if(s==0) dwl(a&(0xff>>(8-p1.y%8)));
499 7 else if(s==0xff) dwl(a|(0xff<<(p1.y%8)));
500 7 else {dwl(a^(0xff<<(p1.y%8)));}
501 7 }
C51 COMPILER V7.06 SPY_LCD 04/22/2007 11:06:48 PAGE 13
502 6 else if(i==max+1)//最下边一页的处理
503 6 {
504 7 if(s==0) dwl(a&(0xff<<(p2.y%8+1)));
505 7 else if(s==0xff) dwl(a|(0xff>>(7-p2.y%8)));
506 7 else {dwl(a^(0xff>>(7-p2.y%8)));}
507 7 }
508 6 else //中间页的处理
509 6 {
510 7 if(s==0) {dwl(0);}
511 7 else if(s==0xff) {dwl(0xff);}
512 7 else {dwl(~a);}
513 7 }
514 6 }
515 5 else
516 5 {
517 6 if(s==0) dwl(a&((0xff>>(8-p1.y%8))|(0xff<<(p2.y%8+1))));
518 6 else if(s==0xff) dwl(a|((0xff<<(p1.y%8))&(0xff>>(7-p2.y%8))));
519 6 else {dwl(a^((0xff<<(p1.y%8))&(0xff>>(7-p2.y%8))));}
520 6 }
521 5 }
522 4 else
523 4 {
524 5 iwr(0xb8|(i-1));
525 5 iwr(0x40|(j-64));
526 5 a=drr();
527 5 a=drr();
528 5 iwr(0x40|(j-64));
529 5 if(min!=max)
530 5 {
531 6
532 6 if(i==min+1)
533 6 {
534 7 if(s==0) {dwr(a&(0xff>>(8-p1.y%8)));}
535 7 else if(s==0xff) {dwr(a|(0xff<<(p1.y%8)));}
536 7 else {dwr(a^(0xff<<(p1.y%8)));}
537 7 }
538 6 else if(i==max+1)
539 6 {
540 7 if(s==0) {dwr(a&(0xff<<(p2.y%8+1)));}
541 7 else if(s==0xff) {dwr(a|(0xff>>(7-p2.y%8)));}
542 7 else {dwr(a^(0xff>>(7-p2.y%8)));}
543 7 }
544 6 else
545 6 {
546 7 if(s==0) {dwr(0);}
547 7 else if(s==0xff) {dwr(0xff);}
548 7 else {dwr(~a);}
549 7 }
550 6 }
551 5 else
552 5 {
553 6 if(s==0) dwr(a&((0xff>>(8-p1.y%8))|(0xff<<(p2.y%8+1))));
554 6 else if(s==0xff) dwr(a|((0xff<<(p1.y%8))&(0xff>>(7-p2.y%8))));
555 6 else {dwr(a^((0xff<<(p1.y%8))&(0xff>>(7-p2.y%8))));}
556 6 }
557 5 }
558 4 }
559 3 }
560 2 }
561 1 }
562
563 /*将8位的字模数据写入光标指定的位置进行显示*/
C51 COMPILER V7.06 SPY_LCD 04/22/2007 11:06:48 PAGE 14
564 void disp_one_modu(uchar m)
565 {
566 1 uchar a;
567 1 if((cursor.x<128)&&(cursor.y<64))
568 1 {
569 2 if(cursor.x<=63)
570 2 {
571 3 iwl(0xb8|cursor.y/8);
572 3 iwl(0x40|cursor.x);
573 3 a=drl();
574 3 a=drl();
575 3 iwl(0x40|cursor.x);
576 3 dwl((m<<(cursor.y%8))|(a&(0xff>>(8-cursor.y%8))));
577 3 if((cursor.y+8)<64)
578 3 {
579 4 iwl(0xb8|(cursor.y+8)/8);
580 4 iwl(0x40|cursor.x);
581 4 a=drl();
582 4 a=drl();
583 4 iwl(0x40|cursor.x);
584 4 dwl((a&(0xff<<(cursor.y%8)))|(m>>(8-cursor.y%8)));
585 4 }
586 3 }
587 2 else
588 2 {
589 3 iwr(0xb8|cursor.y/8);
590 3 iwr(0x40|(cursor.x-64));
591 3 a=drr();
592 3 a=drr();
593 3 iwr(0x40|(cursor.x-64));
594 3 dwr((m<<(cursor.y%8))|(a&(0xff>>(8-cursor.y%8))));
595 3 if((cursor.y+8)<64)
596 3 {
597 4 iwr(0xb8|(cursor.y+8)/8);
598 4 iwr(0x40|(cursor.x-64));
599 4 a=drr();
600 4 a=drr();
601 4 iwr(0x40|(cursor.x-64));
602 4 dwr((a&(0xff<<(cursor.y%8)))|(m>>(8-cursor.y%8)));
603 4 }
604 3 }
605 2 }
606 1 else
607 1 {
608 2 if(cursor.x>=128) zf_ovx=1;
609 2 if(cursor.y>=64) zf_ovy=1;
610 2 }
611 1 }
612
613 /*在光标处显示一个汉字,n是字库中的位置,width表示字符的宽度,pt为字库首地址,s为1表示正显,为0表示反显*/
614 void disp_one_hz(uchar n,uchar width,uchar code *pt,bit s)
615 {
616 1 uchar a,i;
617 1 uint b;
618 1 a=cursor.x;
619 1 zf_ovx=0;
620 1 zf_ovy=0;
621 1 for(i=0;i<width;i++)
622 1 {
623 2 if(zf_ovx==0) {b=i+n*(width<<1);disp_one_modu(s?*(pt+b):~(*(pt+b)));}
624 2 cursor.x++;
625 2 if(cursor.x==128) zf_ovx=1;
C51 COMPILER V7.06 SPY_LCD 04/22/2007 11:06:48 PAGE 15
626 2 }
627 1 zf_ovx=0;
628 1 if((cursor.y+8)<64)//张工编的程序总会执行这句,所以不会出错
629 1 {
630 2 cursor.x=a;
631 2 a=cursor.y;
632 2 cursor.y+=8;
633 2 for(i=width;i<(width<<1);i++)
634 2 {
635 3 if(zf_ovx==0) {b=i+n*(width<<1);disp_one_modu(s?*(pt+b):~(*(pt+b)));}
636 3 cursor.x++;
637 3 if(cursor.x==128) zf_ovx=1;
638 3 }
639 2 }
640 1 cursor.y=a;//有错
641 1 zf_ovx=0;
642 1 zf_ovy=0;
643 1 }
644
645
646
647 /*串口初始化,11.0592晶振,baud rate:9600bps*/
648 void init(void)
649 {
650 1 TMOD=0x21;
651 1 TH1=0xfd;
652 1 TL1=0xfd;
653 1 PCON=0;
654 1 SCON=0x50;
655 1 TR1=1; /*启动T1*/
656 1 ES=1; /*开串口中断*/
657 1 }
658
659 /*串口中断子程序*/
660 void serial(void) interrupt 4 using 2
661 {
662 1 if(RI)
663 1 {
664 2 if((SBUF==0x1b)&&(sum==0)) {istart=1;iend=0;shuju[0]=0x1b;} //是正常数据么?
665 2 else
666 2 { if(istart==1) //
667 3 { sum=sum+1;
668 4 if(sum<=3) {shuju[sum]=SBUF;
669 5 if(sum==3) {sum=0; iend=1;istart=0;} //复位各状态标志
670 5 }
671 4
672 4 }
673 3 }
674 2 RI=0;
675 2 }
676 1 }
677
678
679
680 void transfer(uint a) //显示数字:0~65535
681 {
682 1 if(a>=0&&a<10) //判断a是否为个位数
683 1 {disp_one_hz(a,5,numeric,1);} //显示个位数
684 1 else if(a>=10&&a<100)//判断a是否为十位数
685 1 {
686 2 disp_one_hz(a/10,5,numeric,1);//显示十位数
687 2 disp_one_hz(a%10,5,numeric,1);//显示个位数
C51 COMPILER V7.06 SPY_LCD 04/22/2007 11:06:48 PAGE 16
688 2 }
689 1 else if(a>=100&&a<1000)//判断a是否为百位数
690 1 {disp_one_hz(a/100,5,numeric,1);//显示百位数
691 2 a=a%100;
692 2 disp_one_hz(a/10,5,numeric,1);//显示十位数
693 2 disp_one_hz(a%10,5,numeric,1);//显示个位数
694 2 }
695 1 else if(a>=1000&&a<10000)//判断a是否为千位数
696 1 {disp_one_hz(a/1000,5,numeric,1);//显示千位数
697 2 a=a%1000;
698 2 disp_one_hz(a/100,5,numeric,1);//显示百位数
699 2 a=a%100;
700 2 disp_one_hz(a/10,5,numeric,1);//显示十位数
701 2 disp_one_hz(a%10,5,numeric,1);//显示个位数
702 2 }
703 1 else if(a==65535)
704 1 {disp_one_hz(6,5,numeric,1);
705 2 disp_one_hz(5,5,numeric,1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -