📄 sms.lst
字号:
556 1 error_counter=0;
557 1 if(high_flag)
558 1 byte_length=17;
559 1 else
560 1 byte_length=16;
561 1 while(1)
562 1 {
563 2 TI0=0;
564 2 RI0=0;
565 2 Serial0_Inter_Close();
566 2 uart0_send(Command_Cmgd,8);
567 2 if(high_flag)
568 2 {
569 3 SBUF0 =index_high;
570 3 while(!TI0); TI0 = 0;
571 3 }
572 2 SBUF0 =index_low;
573 2 while(!TI0); TI0 = 0;
574 2 SBUF0 ='\r';
575 2 while(!TI0); TI0 = 0;
576 2 start_timer0();
577 2 for(i=0;i<byte_length;i++)
578 2 {
579 3 while(!RI0);
580 3 rec[i]=SBUF0;
581 3 RI0=0;
582 3 }
583 2 close_timer0();
584 2 if((!high_flag&&rec[12]== 'O'&& rec[13]== 'K')||(high_flag&&rec[13]== 'O'&& rec[14]== 'K')) break;
-
585 2 else if(error_counter++<10) Delay_1S();
586 2 else deal_with_error();
587 2 }
588 1 RI0=0;
589 1 TI0=0;
590 1 Serial0_Inter_Open();
591 1 Delay10ms();
592 1 }
593 void Serial0_Service(void) interrupt 4
594 {
595 1 static unsigned char i=0;
596 1 static bit cmti_flag=0;
597 1 unsigned char j;
598 1 unsigned char xdata buffer[16];
599 1 unsigned char temp;
600 1 if(RI0)
601 1 {
602 2 temp=SBUF0;
603 2 RI0=0; //清接收标志
604 2 if(temp=='+')
605 2 {
606 3 buffer[0]='+';
607 3 for(j=1;j<16;j++)
608 3 buffer[j]=0;
C51 COMPILER V7.02a SMS 08/28/2005 17:10:47 PAGE 11
609 3 i=1;
610 3 }
611 2 else
612 2 {
613 3 if(i<16)
614 3 buffer[i++]=temp;
615 3 if(i==5)
616 3 {
617 4 if(buffer[1]=='C'&&buffer[2]=='M'&&buffer[3]=='T'&&buffer[4]=='I')
618 4 cmti_flag=1;
619 4 else
620 4 cmti_flag=0;
621 4 }
622 3 else
623 3 if(cmti_flag&&i==15)
624 3 {
625 4 cmti_flag=0;
626 4 if(buffer[13]==0x0D&&buffer[14]==0x0A)
627 4 {
628 5 sms_index[sms_index_len][0]='0';
629 5 sms_index[sms_index_len++][1]=buffer[12];
630 5 }
631 4 else
632 4 if(buffer[14]==0x0D)
633 4 {
634 5 sms_index[sms_index_len][0]=buffer[12];
635 5 sms_index[sms_index_len++][1]=buffer[13];
636 5 }
637 4 else
638 4 deal_with_error();
639 4 }
640 3 }
641 2 }
642 1
643 1 }
644
645
646 unsigned int String2Bytes(const char* pSrc, unsigned char* pDst,const int nSrcLength)
647 {
648 1 unsigned int i;
649 1 for ( i = 0; i < nSrcLength; i += 2)
650 1 {
651 2 // 输出高4位
652 2 if ((*pSrc >= '0') && (*pSrc <= '9'))
653 2 {
654 3 *pDst = (*pSrc - '0') << 4;
655 3 }
656 2 else
657 2 {
658 3 *pDst = (*pSrc - 'A' + 10) << 4;
659 3 }
660 2
661 2 pSrc++;
662 2
663 2 // 输出低4位
664 2 if ((*pSrc>='0') && (*pSrc<='9'))
665 2 {
666 3 *pDst |= *pSrc - '0';
667 3 }
668 2 else
669 2 {
670 3 *pDst |= *pSrc - 'A' + 10;
C51 COMPILER V7.02a SMS 08/28/2005 17:10:47 PAGE 12
671 3 }
672 2
673 2 pSrc++;
674 2 pDst++;
675 2 }
676 1
677 1 // 返回目标数据长度
678 1 return (nSrcLength/2);
679 1 }
680 unsigned char DecodeUcs2(const unsigned char* pSrc, char* pDst,const int nSrcLength)
681 {
682 1 unsigned short nDstLength; // UNICODE宽字符数目
683 1 unsigned short i,j;
684 1 unsigned char temp_h,temp_l;
685 1 nDstLength=nSrcLength>>1;
686 1 for(j=0;j<nDstLength;j++)
687 1 {
688 2 //得到两个字节的数据,先取高位,后取低位
689 2 temp_h=*pSrc;
690 2 temp_l=*(pSrc+1);
691 2 pSrc+=2;
692 2 if(temp_h==0x00)//如果高位字节为0x00,表明是Ascii表中数据,从0x20-0x7e,将其处理成语音芯片要求的GB231
-2格式
693 2 {
694 3 if(temp_l==0x0a||temp_l==0x0d)
695 3 {
696 4 *pDst++=0xa3;
697 4 *pDst++=0xa0;//将0x0a,0x0d当作空格处理
698 4 }
699 3 else
700 3 if(temp_l>=0x20&&temp_l<0x7f)
701 3 {
702 4 *pDst++=0xa3;
703 4 *pDst++=temp_l+0x80;
704 4 }
705 3 }
706 2 else
707 2 {
708 3 for(i=0;i<13536;i=i+2)
709 3 if(temp_h==gb2ucs_lookup[i]&&temp_l==gb2ucs_lookup[i+1])
710 3 break;
711 3 if(i==13536)//查找表中没有找到,则返回&
712 3 {
713 4 *pDst++=0xa3;
714 4 *pDst++=0xa6;
715 4 }
716 3 else
717 3 {
718 4 *pDst++=(i>>1)/94+0xB0;
719 4 *pDst++=(i>>1)%94+0xA1;
720 4 }
721 3 }//else
722 2 }//for
723 1 return nDstLength;
724 1 }
725 //========sms有关的函数结束===================
726 /****************************
727 open and close leds
728 ****************************/
729
730 void led1_open()
731 { led1=1; }
C51 COMPILER V7.02a SMS 08/28/2005 17:10:47 PAGE 13
732
733 void led1_close()
734 { led1=0; }
735
736 void led2_open()
737 { led2=1; }
738
739 void led2_close()
740 { led2=0; }
741
742 void led3_open()
743 {
744 1 led3=1;
745 1 }
746
747 void led3_close()
748 {
749 1 led3=0;
750 1 }
751
752 //===================================
753 //***************delay 1s***********
754 void Delay_1S(void)
755 {
756 1 UCHAR idata i;
757 1 for(i=0;i<100;i++) Delay10ms();
758 1 }
759 //=================================
760
761 //********延时子程序*********
762 //*********************************
763
764 void Delay10ms()
765 {
766 1 UINT idata i;
767 1 for(i=0;i<10000;i++);
768 1 }
769
770
771 void start_timer0(void)
772 {
773 1 timer0_counter=0;
774 1 CKCON &= 0xF7; //设置定时器0为系统时钟12分频T0M=0
775 1 TH0=0x00;
776 1 TL0=0x00;
777 1 TMOD = 0x01; //设置定时器0为模式1(定时器1为模式0)
778 1 TCON &= 0xDF; //清定时器0溢出中断标志TF0
779 1 ET0=1; //允许定时器0溢出中断
780 1 TCON |=0x10; //开启定时器0
781 1 }
782
783 void close_timer0(void)
784 {
785 1 timer0_counter=0;
786 1 TCON &=0xEF;
787 1 ET0=0;
788 1 }
789 //deal with overtime error
790 void timer0(void) interrupt 1
791 {
792 1 if(timer0_counter++>250)//error times over 250
793 1 deal_with_error();
C51 COMPILER V7.02a SMS 08/28/2005 17:10:47 PAGE 14
794 1 }
795 //led1,2,3 all open when error occures
796 void deal_with_error(void)
797 {
798 1 led1_open();
799 1 led2_open();
800 1 led3_open();
801 1 send(0xf4);
802 1 disp_chn(error_display,16);
803 1 while(1);
804 1 }
805
806 /*************************LCD module ***************************************
807
808 ****************************************************************************/
809
810 void send (UCHAR dat)
811 {
812 1 LCD_REQ=0;
813 1 while(LCD_BUSY==1);//wait until LCD is free
814 1 LCD_DATA=dat; //put data on the bus
815 1 LCD_REQ=1; //use LCD_REQ to latch the data into OCMJ
816 1 while(LCD_BUSY==0);// wait until LCD deals with the request
817 1 LCD_REQ=0; //
818 1 }
819
820 /*write data or command */
821 void wr_zb (UCHAR comm,UCHAR addr_x,UCHAR addr_y)
822 {
823 1 send(comm);
824 1 send(addr_x);
825 1 send(addr_y);
826 1 }
827
828 /*--------------display dot array------------------*/
829 void disp_lat (UCHAR data1,UCHAR data2)
830 {
831 1 UCHAR i,j,k;
832 1 for(k=0;k<32;k=k+4)
833 1 {
834 2 for(j=0;j<2;j++)
835 2 {
836 3 for(i=0;i<16;i++)
837 3 {
838 4 wr_zb(0xf3,i,k+j);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -