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

📄 sms.lst

📁 这是一个单片机控制TC35I无线通信模块源程序。通过短信通讯。
💻 LST
📖 第 1 页 / 共 4 页
字号:
 276   1      }
 277          
 278          
 279          
 280          /***********AT+cmgf*************
 281          set preferred message format:text mode or PDU mode
 282          In PDU mode, a complete SMS Message including all header information is passed
 283          as a binary string (in hexadecimal format, so only this set of characters is allowed :
 284          {‘0’,’1’,’2’,’3’,’4’,’5’,’6’,’7’,’8’,’9’, ‘A’, ‘B’,’C’,’D’,’E’,’F’} ). Eac
             -h pair or characters is converted to
 285          a byte (ex : ‘41’ is converted to the ASCII character ‘A’, whoes ASCII code is 0x41 or 65).
 286          In Text mode, every commands and responses are in ASCII characters.
 287          ********************************/
 288          void    AT_cmgf(void)
 289          {
 290   1              UCHAR idata     i;
 291   1          while(1)                                           // AT+CSQ
 292   1          {
 293   2                      TI0=0;
 294   2                      RI0=0;
 295   2                      /*
 296   2              for(i=0;i<10;i++)
 297   2              {
 298   2                SBUF0 = Command_Cmgf[i];
 299   2                while(!TI0); TI0 = 0;
 300   2              }
 301   2              */
C51 COMPILER V7.02a   SMS                                                                  08/28/2005 17:10:47 PAGE 6   

 302   2                      uart0_send(Command_Cmgf,10);
 303   2                      break;
 304   2                      Delay_1S();
 305   2          }
 306   1              Delay_1S();
 307   1          RI0=0;
 308   1              TI0=0;
 309   1      }
*** WARNING C280 IN LINE 290 OF SMS.C: 'i': unreferenced local variable
 310          /***********AT+cmgf*************
 311          set preferred message format:text mode or PDU mode
 312          In PDU mode, a complete SMS Message including all header information is passed
 313          as a binary string (in hexadecimal format, so only this set of characters is allowed :
 314          {‘0’,’1’,’2’,’3’,’4’,’5’,’6’,’7’,’8’,’9’, ‘A’, ‘B’,’C’,’D’,’E’,’F’} ). Eac
             -h pair or characters is converted to
 315          a byte (ex : ‘41’ is converted to the ASCII character ‘A’, whoes ASCII code is 0x41 or 65).
 316          In Text mode, every commands and responses are in ASCII characters.
 317          ********************************/
 318          /*
 319          void    AT_cmgf(void)
 320          {
 321                  UCHAR idata     i,error_counter;
 322                  error_counter=0;
 323          
 324              while(1)                                           // AT+CSQ
 325              {
 326                          TI0=0;
 327                          RI0=0;
 328                          start_timer0();
 329                  for(i=0;i<10;i++)
 330                  {
 331                    SBUF0 = Command_Cmgf[i];
 332                    while(!TI0); TI0 = 0;
 333                  }       
 334                                  for(i=0;i<16;i++)                                                       //only receive part data (10)
 335                  {
 336                    while(!RI0);
 337                    rec[i] = SBUF0;
 338                    RI0 = 0;
 339                      }
 340                      close_timer0();
 341                  if(rec[12]!= 'O'&& rec[13]!= 'K')break;  
 342                  else if(error_counter++<10)     Delay_1S();
 343                                          else deal_with_error();
 344              }
 345                  Delay_1S();
 346              RI0=0;
 347                  TI0=0;
 348          }
 349          */
 350          /***********AT_cmgs****************************************
 351          Send message function
 352          After sending "CMGS" command,there will be 16 bytes received,
 353          among which the 15th and 16th must be "0x3E"and "0x20"
 354          ***********AT+cmgs函数开始********************************/
 355          void    AT_cmgs(void)
 356          {
 357   1              UCHAR idata     i;
 358   1          while(1)                                           // AT+cmgs
 359   1          {
 360   2                      TI0=0;
 361   2                      RI0=0;
C51 COMPILER V7.02a   SMS                                                                  08/28/2005 17:10:47 PAGE 7   

 362   2                      /*
 363   2              for(i=0;i<12;i++)
 364   2              {
 365   2                SBUF0 = Command_Cmgs[i];
 366   2                while(!TI0); TI0 = 0;
 367   2              }
 368   2                      */
 369   2                      uart0_send(Command_Cmgs,12);
 370   2                      start_timer0();
 371   2              for(i=0;i<16;i++)                                                       
 372   2              {
 373   3                while(!RI0);
 374   3                rec[i] = SBUF0;
 375   3                RI0 = 0;
 376   3                  }
 377   2              close_timer0();
 378   2              if(rec[14]== 0x3E&& rec[15]== 0x20)
 379   2                      break;          
 380   2              //      Delay_1S();
 381   2          }
 382   1      
 383   1      //                      Delay_1S();
 384   1                              for(i=0;i<50;i++);              //延时一段时间
 385   1                      RI0=0;
 386   1                              TI0=0;
 387   1      }
 388          
 389          //***********AT+cmgs函数结束*************
 390          //========sms有关的函数结束===================
 391          
 392          //发送GSMhead[],Phone_number,GSM_set[],GSM_sms[],0x1A;
 393          //***********SEND_sms函数开始*************
 394          void    SEND_sms(void)
 395          {
 396   1               UCHAR idata    i;
 397   1       //   while(1)                                           
 398   1          {
 399   2                      TI0=0;
 400   2                      RI0=0;
 401   2                      //send GSMhead(12 bytes)
 402   2              for(i=0;i<12;i++)
 403   2              {
 404   3                SBUF0 = GSMhead[i];
 405   3                while(!TI0); TI0 = 0;
 406   3              }
 407   2              //send phone number(12 bytes)
 408   2                      for(i=0;i<12;i++)
 409   2              {
 410   3                SBUF0 = Center_number[i];
 411   3                while(!TI0); 
 412   3                        TI0 = 0;
 413   3              }
 414   2              //send GSM_set(6 bytes)
 415   2                      for(i=0;i<6;i++)
 416   2              {
 417   3                SBUF0 = GSM_set[i];
 418   3                while(!TI0); TI0 = 0;
 419   3              }
 420   2                      //send sms contents(26 bytes)
 421   2                      for(i=0;i<26;i++)
 422   2              {
 423   3                SBUF0 = GSM_sms[i];
C51 COMPILER V7.02a   SMS                                                                  08/28/2005 17:10:47 PAGE 8   

 424   3                while(!TI0); TI0 = 0;
 425   3              }
 426   2              //send end bytes:0x1A
 427   2                      SBUF0=0x1A;
 428   2                      while(!TI0); TI0 = 0;   //发送信息结束
 429   2      /*
 430   2              for(i=0;i<75;i++)                                               
 431   2              {
 432   2                while(!RI0);
 433   2                rec[i] = SBUF0;
 434   2                RI0 = 0;
 435   2                  }
 436   2                       if(rec[72]== 'O'&& rec[73]== 'K')break;  
 437   2      */      
 438   2              Delay_1S();
 439   2      
 440   2          }
 441   1      
 442   1      
 443   1      //                      Delay_1S();
 444   1                              for(i=0;i<255;i++);             //延时一段时间
 445   1                      RI0=0;
 446   1                              TI0=0;
 447   1      }
 448          
 449          
 450          //***********SEND_sms函数结束*************
 451          
 452          void    AT_cnmi(void)
 453          {
 454   1               UCHAR idata i,error_counter;
 455   1           error_counter=0;
 456   1               Serial0_Inter_Close();
 457   1               while(1)
 458   1               {
 459   2              TI0=0;
 460   2                      RI0=0;
 461   2              uart0_send(Command_Cnmi,18);
 462   2                      start_timer0();
 463   2              for(i=0;i<24;i++)                                                       //only receive part data (10)
 464   2              {
 465   3                while(!RI0);
 466   3                rec[i] = SBUF0;
 467   3                RI0 = 0;
 468   3                  }
 469   2                  close_timer0();
 470   2             
 471   2              if(rec[20]== 'O'&& rec[21]== 'K') break;  
 472   2              else if(error_counter++<10)     Delay_1S();
 473   2                                      else deal_with_error();
 474   2             }
 475   1              Serial0_Inter_Open();
 476   1              Delay_1S();
 477   1          RI0=0;
 478   1      }
 479          
 480          //+CMGR: 3,,20
 481          unsigned char AT_cmgr(unsigned char index_high,unsigned char index_low,unsigned char buffer[])
 482          {
 483   1              UCHAR idata     i;
 484   1              UCHAR byte_length=0;
 485   1              UCHAR length;
C51 COMPILER V7.02a   SMS                                                                  08/28/2005 17:10:47 PAGE 9   

 486   1              UCHAR temp;
 487   1                      TI0=0;
 488   1                      RI0=0;
 489   1                        if(index_high=='0')
 490   1                          byte_length=82;
 491   1                        else
 492   1                          byte_length=83;
 493   1                      Serial0_Inter_Close();
 494   1                      uart0_send(Command_Cmgr,8);
 495   1                      if(index_high!='0')
 496   1                        {
 497   2              SBUF0 =index_high;
 498   2              while(!TI0); TI0 = 0;
 499   2                }
 500   1              SBUF0 =index_low;
 501   1              while(!TI0); TI0 = 0;
 502   1                      SBUF0 ='\r';
 503   1              while(!TI0); TI0 = 0;
 504   1              start_timer0();
 505   1              for(i=0;i<byte_length;i++)
 506   1                        {
 507   2                          while(!RI0);
 508   2                temp = SBUF0;
 509   2                RI0 = 0;
 510   2                        }
 511   1                        //接收两个字节的短信长度字符
 512   1                        //短信长度高位
 513   1                    while(!RI0);
 514   1                temp = SBUF0;
 515   1                RI0 = 0; 
 516   1                if((temp>='0')&&(temp<='9'))
 517   1                          length=(temp-'0')<<4;
 518   1                        else
 519   1                          length=(temp-'A'+10)<<4;
 520   1                        //短信长度低位
 521   1                        while(!RI0);
 522   1                temp = SBUF0;
 523   1                RI0 = 0; 
 524   1                if((temp>='0')&&(temp<='9'))
 525   1                          length|=(temp-'0');
 526   1                        else
 527   1                          length|=(temp-'A'+10);
 528   1                              //length*2个短信内容字符
 529   1                        for(i=0;i<length*2;i++)
 530   1                          {
 531   2                                while(!RI0);
 532   2                          buffer[i]=SBUF0;
 533   2                                RI0=0;
 534   2                              }
 535   1                        for(i=0;i<8;i++)
 536   1                          {
 537   2                                while(!RI0);
 538   2                             temp=SBUF0;
 539   2                                RI0=0;                          
 540   2                              }
 541   1                      close_timer0();
 542   1              Serial0_Inter_Open();
 543   1              Delay_1S();
 544   1          RI0=0;
 545   1              TI0=0;
 546   1          return length*2;
 547   1      }
C51 COMPILER V7.02a   SMS                                                                  08/28/2005 17:10:47 PAGE 10  

 548          
 549          
 550          
 551          void    AT_cmgd(unsigned char index_high,unsigned char index_low)
 552          {
 553   1              UCHAR idata i,error_counter;
 554   1              bit high_flag=(index_high!='0');
 555   1              UCHAR byte_length=0;

⌨️ 快捷键说明

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