⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smsdrive.lst

📁 51单片机控制TC35模块的程序
💻 LST
📖 第 1 页 / 共 4 页
字号:
 585   3                       if(rec[14]=='O'&&rec[15]=='K')    
 586   3                     {
 587   4                                   deal_with_right();
 588   4                                       flag=0;
 589   4                       count=0;  
 590   4                                       break;
 591   4                                 }//如果第15和第16个字符分别是“O和“K”,那说明正确,直接退出,否则就说明出错了
 592   3      
 593   3                     else  
 594   3                       {
 595   4                         deal_with_error();
 596   4                                         flag=0;
 597   4                         count=0; 
 598   4                       }         //出错,进入下一次循环
 599   3                 
 600   3                   }     
 601   2      
 602   2           }
 603   1      }
 604          
 605          /*===========================================
 606          *函数名:TC35读取短消息 子函数
 607          *参  数:
 608          *功  能:
 609          *返回值:
 610          *作  者:weishao2401  2009/4/29
C51 COMPILER V7.08   SMSDRIVE                                                              04/12/2010 21:34:57 PAGE 11  

 611          *============================================*/
 612          
 613          /*===========================================
 614          AT+CMGR=7
 615          +CMGR: 1,,23
 616          [0891][683108301505F0][040D91][683164865667F7][0000][90607051008123][03][31D90C]
 617          
 618          OK
 619          
 620          41 54 2B 43 4D 47 52 3D 37 0D 0D 0A 2B 43 4D 47 52 3A 20 31 2C 2C 32 33 0D 0A [30 38 39 31 36 38 33 31 30 
             -38 33 30 31 35 30 35 46 30 30 34 30 44 39 31 36 38 33 31 36 34 38 36 35 36 36 37 46 37 30 30 30 30 39 30 36 30 37 30 35 
             -31 30 30 38 31 32 33 30 33 33 31 44 39 30 43] 0D 0A 0D 0A 4F 4B 0D 0A  
 621          前26个字符是状态显示的,27开始是数据,倒数8个也是命令格式方面的。 
 622          *============================================*/
 623          void TC35_AtCmgd();
 624                      
 625          void TC35_AtCmgr()          // TC35读取短消息
 626          {
 627   1                                          
 628   1                                              
 629   1                                       
 630   1            TI=0;
 631   1            RI=0;
 632   1            uart_send(Command_Cmgr,10);       // AT+CMGR=
 633   1            
 634   1            deal_with_attention(); 
 635   1      
 636   1                DelayMs(250);                 //延时,等待TC35的反馈信息
 637   1                DelayMs(250);
 638   1                DelayMs(250);
 639   1                DelayMs(250); 
 640   1                DelayMs(250);   
 641   1           
 642   1      
 643   1      //        TC35_AtCmgd();        
 644   1                                   //出错,进入下一次循环
 645   1              
 646   1                  
 647   1      
 648   1          
 649   1      }
 650          
 651          /*===========================================
 652          *函数名:TC35删除短消息 子函数
 653          *参  数:
 654          *功  能:
 655          *返回值:
 656          *作  者:weishao2401  2009/4/29
 657          *============================================*/
 658          
 659          /*===========================================
 660          接收到:41 54 2B 43 4D 47 44 3D 36 0D 0D 0A 4F 4B 0D 0A
 661          对应字符:
 662          AT+CMGD=6<CR>
 663          OK
 664          *============================================*/
 665          
 666          void TC35_AtCmgd()          // TC35删除短消息
 667          {
 668   1                                                   
 669   1             ydl=0;                                  
 670   1         
C51 COMPILER V7.08   SMSDRIVE                                                              04/12/2010 21:34:57 PAGE 12  

 671   1            TI=0;
 672   1            RI=0;
 673   1               
 674   1            uart_send(Command_Cmgd,10);       // AT+CMGD=
 675   1            
 676   1            
 677   1         
 678   1            deal_with_attention(); 
 679   1      
 680   1                DelayMs(250);                 //延时,等待TC35的反馈信息
 681   1                DelayMs(250);
 682   1                DelayMs(250);
 683   1      
 684   1               {  if(flag == 1&& count == 16)
 685   2                   { 
 686   3                       if(rec[12]=='O'&&rec[13]=='K')    
 687   3                     {
 688   4                                   deal_with_right();
 689   4                                       flag=0;
 690   4                       count=0;  
 691   4                                      
 692   4                                 }
 693   3      
 694   3                     else  
 695   3                       {
 696   4                         deal_with_error();
 697   4                                         flag=0;
 698   4                         count=0; 
 699   4                       }         //出错,进入下一次循环
 700   3                 
 701   3                   }     
 702   2      
 703   2           }
 704   1      
 705   1      }
 706          
 707          
 708          /*===========================================
 709          *函数名:TC35 初始化 子函数
 710          *参   数:
 711          *功   能:
 712          *返回值:
 713          *作  者:weishao2401  2009/4/29
 714          *============================================*/
 715          
 716          void TC35_Init(void)
 717          {
 718   1          TC35_AtSend();        //AT联机测试
 719   1              DelayMs(250);
 720   1              DelayMs(250);
 721   1                       
 722   1          TC35_SignalTest();     //TC35信号测试
 723   1          DelayMs(250);
 724   1              DelayMs(250);
 725   1      
 726   1          TC35_ATE1() ;
 727   1          DelayMs(250);       
 728   1              DelayMs(250);
 729   1      
 730   1              //TC35_ATV1() ;
 731   1          //DelayMs(250);     
 732   1      //      DelayMs(250);
C51 COMPILER V7.08   SMSDRIVE                                                              04/12/2010 21:34:57 PAGE 13  

 733   1      
 734   1          TC35_AtCmgf1();        //TC35短信格式设置,设为 文本格式
 735   1          DelayMs(250);       
 736   1              DelayMs(250);
 737   1              
 738   1          TC35_AtCscs();      //TC35显示字符设置,设为 GSM字符
 739   1          DelayMs(250);       
 740   1              DelayMs(250);
 741   1      
 742   1              TC35_AtCnmi();      // TC35新消息提示设置,设置为来消息提示
 743   1          DelayMs(250);       
 744   1          DelayMs(250);
 745   1      
 746   1              
 747   1      }   
 748          
 749          
 750          
 751          
 752          /*===========================================
 753          *函数名:TC35 文本短信发送 子函数
 754          *参   数:U8 User_ID
 755          *功   能:选择用户User_ID,给他发送短信
 756          *返回值:
 757          *作  者:weishao2401  2009/4/29
 758          *============================================*/
 759          
 760          void TC35_AtCmgsT(U8 User_ID)   // 发送短信 子函数
 761          {                                  
 762   1          while(1)                                      
 763   1          {
 764   2            TI=0;
 765   2            RI=0;
 766   2            switch(User_ID)
 767   2            {
 768   3              case 1: uart_send(Command_CmgsT1,20);   break;    // 给用户1发短信 
 769   3              case 2: uart_send(Command_CmgsT2,20);   break;    // 给用户2发短信 
 770   3            //   case 3: uart_send(Command_CmgsT3,20);   break;    // 给用户3发短信 
 771   3            //   case 4: uart_send(Command_CmgsT4,20);   break;    // 给用户4发短信 
 772   3              default: deal_with_error(); break;
 773   3            }
 774   2      
 775   2            deal_with_attention(); 
 776   2      
 777   2                       DelayMs(250);          //延时,等待TC35的反馈信息
 778   2                 DelayMs(250);
 779   2                  DelayMs(250);
 780   2                      DelayMs(250);  
 781   2                      
 782   2              if(flag == 1 && count == 24)
 783   2                   { 
 784   3                        if(rec[22]==0x3E && rec[23]==0x20)  
 785   3                     {
 786   4                                   deal_with_right();
 787   4                                       flag=0;
 788   4                       count=0;  
 789   4                                       break;
 790   4                                 }//如果第23和第24个字符分别是“>"和“空格”,那说明正确,直接退出,否则就说明出错了
 791   3      
 792   3                     else  
 793   3                       {
 794   4                         deal_with_error();
C51 COMPILER V7.08   SMSDRIVE                                                              04/12/2010 21:34:57 PAGE 14  

 795   4                                         flag=0;
 796   4                         count=0; 
 797   4                       }         //出错,进入下一次循环
 798   3                 
 799   3                   }     
 800   2      
 801   2           }
 802   1      } 
 803          
 804          
 805          
 806          /*===========================================
 807          *函数名:TC35 文本内容填装 子函数
 808          *参   数:U8 data2_buffer[] ,U8 User_ID 
 809          *功   能:把data2_buffer[]中的内容加为短信内容,如果装填内容失败,重给User_ID用户发送短信
 810          *返回值:
 811          *作  者:weishao2401  2009/4/29
 812          *============================================*/
 813          
 814          /*===========================================
 815          * U8 code Content_warning[30] = "warning:gas leakage!\x1a";
 816          *发送:77 61 72 6E 69 6E 67 3A 67 61 73 20 6C 65 61 6B 61 67 65 21 1A
 817          *接收到:77 61 72 6E 69 6E 67 3A 67 61 73 20 6C 65 61 6B 61 67 65 21 1A
 818          *          0D 0A 2B 43 4D 47 53 3A 20 32 30 32 0D 0A 0D 0A 4F 4B 0D 0A
 819          *对应字符:
 820          *         warning:gas leakage!
 821          *         +CMGS: 202
 822          *        
 823          *        OK
 824          *============================================*/  
 825              
 826          void TC35_ContentLoad(U8 data2_buffer[],U8 User_ID)        // 文本内容填装 子函数
 827          {
 828   1            U8 len,i;
 829   1            len = strlen(data2_buffer);
 830   1      
 831   1                 
 832   1                 while(1)  
 833   1                 { 
 834   2                   uart_send(data2_buffer,len);   //导入短信内容,发送  
 835   2               deal_with_attention(); 
 836   2            
 837   2               for(i=0;i<18;i++)          //长延时,发送短信时等待时间很长
 838   2                 {  DelayMs(250);  DelayMs(250); }  
 839   2                                      
 840   2               if(flag == 1)
 841   2                     { 
 842   3                        if(rec[(len+2)]==0x2B && rec[(len+3)]==0x43)  
 843   3                     {
 844   4                                   deal_with_right();
 845   4                                       flag=0;
 846   4                       count=0;
 847   4                                   sendflag=1;
 848   4                                   break;
 849   4                                 }//如果第23和第24个字符分别是“>"和“空格”,那说明正确,直接退出,否则就说明出错了
 850   3      
 851   3                    else  
 852   3                        {
 853   4                         deal_with_error();
 854   4                                         flag=0;
 855   4                         count=0;
 856   4                                         sendflag=0;
C51 COMPILER V7.08   SMSDRIVE                                                              04/12/2010 21:34:57 PAGE 15  

 857   4                         TC35_AtCmgsT(User_ID);
 858   4                         DelayMs(250);
 859   4                         DelayMs(250);
 860   4                         DelayMs(250);
 861   4                         }         //出错,进入下一次循环
 862   3                 
 863   3                       }  
 864   2                        else  
 865   2                  {
 866   3                         deal_with_error();
 867   3                                         flag=0;
 868   3                         count=0; 
 869   3                                         sendflag=0;
 870   3                         //TC35_AtCmgsT(User_ID);
 871   3                         DelayMs(250);
 872   3                         DelayMs(250);
 873   3                         DelayMs(250);
 874   3                   }         //出错,进入下一次循环
 875   2                       
 876   2              } 
 877   1      }
 878          
 879          

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -