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

📄 m32.lst

📁 这是用W77E58编写的控制GSM模块
💻 LST
📖 第 1 页 / 共 5 页
字号:
 247   7                                                putstring1("\r\n"); 
 248   7                                            if(phone==1)return Number;               
 249   7                                                        if(strncmp(Number,TPA,strlen(TPA))==0)
 250   7                                {
 251   8                                    //is right number,go on next. 
 252   8                                                        return Number; 
 253   8                    
 254   8                                            }
 255   7                                return NULL;                            
 256   7                                                }
 257   6                                         }//for(i=0;i<16;i++)
 258   5                                     
 259   5                                       }//if(strncpy(SCA,ptr,16) != NULL)      
 260   4                         
 261   4                            }//if((ptr=strstr(ptr,",\"")) != NULL)
 262   3                    else
 263   3                                return NULL;
 264   3                         }//if((ptr=strstr(ans,"+CPBF: ")) != NULL)
 265   2                     else
 266   2                         return NULL;
 267   2                } //while(1)
 268   1            
 269   1      }
 270          
 271          
 272          
 273          
 274          #if 1
 275          int gsmGetRightNumber(uchar* text)
 276          {
 277   1           uchar xdata* ptr;
 278   1               
 279   1               if((ptr=gsmCheckRightNumber(text,1))==NULL) return 0;
 280   1               strcpy(TPA,ptr);
 281   1       
 282   1           
 283   1               putstring1("You have Right Name is:\r\n");
 284   1           putstring1(text);
 285   1           putstring1("\r\n");
 286   1           putstring1("You have Right Number is:\r\n");
 287   1           putstring1(TPA);
 288   1           putstring1("\r\n");
 289   1           return 1;              
 290   1                 
 291   1      }
 292          #endif
 293          
 294          
C51 COMPILER V7.50   M32                                                                   04/04/2007 15:01:44 PAGE 6   

 295          
 296          
 297          
 298          BOOL gsmSendMessage(void) 
 299          {     
 300   1              int  xdata nPduLength;                           // PDU串长度     
 301   1              unsigned char  xdata nSmscLength;                // SMSC串长度     
 302   1              int   xdata nLength;                             // 串口收到的数据长度     
 303   1          uchar xdata* ptr;     
 304   1         
 305   1              TPA[0]=SCA[0];
 306   1          TPA[1]=SCA[1];
 307   1      
 308   1      
 309   1          putstring1("Send Message Start:\r\n");
 310   1          putstring1("SCA=:\r\n");
 311   1          putstring1(SCA);
 312   1          putstring1("\r\n");
 313   1              putstring1("TPA=:\r\n");
 314   1          putstring1(TPA);
 315   1          putstring1("\r\n");
 316   1               
 317   1         
 318   1              nPduLength = gsmEncodePdu(pdu);           // 根据PDU参数,编码PDU串 
 319   1              strcat(pdu, "\x01a");                     // 以Ctrl-Z结束          
 320   1              gsmString2Bytes(pdu, &nSmscLength, 2);    // 取PDU串中的SMSC信息长度     
 321   1              nSmscLength++;                            // 加上长度字节本身    
 322   1                                                        // 命令中的长度,不包括SMSC信息长度,以数据字节计     
 323   1              sprintf(cmd, "AT+CMGS=%d\r", nPduLength/2 - nSmscLength);    // 生成命令          
 324   1         
 325   1              while(1)
 326   1              {
 327   2                 ATSend(cmd);
 328   2             ReadSerail(ans, 128, &nLength,5);
*** WARNING C214 IN LINE 328 OF M32.C: 'Argument': conversion: pointer to non-pointer
 329   2             if((ptr=strstr(ans,"\r\n> ")) != NULL)
 330   2                 {
 331   3                 
 332   3                  ATSend(pdu);  // 得到肯定回答,继续输出PDU串
 333   3                      ReadSerail(ans, 128, &nLength,5);
*** WARNING C214 IN LINE 333 OF M32.C: 'Argument': conversion: pointer to non-pointer
 334   3                  if((strstr(ans, "+CMGS: ")) == NULL)
 335   3                              {
 336   4                                 putbyte('\r');
 337   4                                 delay_ms(20);
 338   4                                     putstring1("SMSC Send Ok!\r\n"); 
 339   4                                         
 340   4                                         return 1;
 341   4                  }
 342   3                          else
 343   3                              {
 344   4                          putstring1("SMSC ANSWER:Err\r\n"); 
 345   4                                      putstring1(ans); 
 346   4                                      putstring1("\r\n"); 
 347   4                              
 348   4                                              
 349   4                                              putbyte('\r');
 350   4                                      delay_ms(20);
 351   4                              ATSend("AT\r\n");
 352   4                          delay_ms(200);
 353   4      
 354   4      
C51 COMPILER V7.50   M32                                                                   04/04/2007 15:01:44 PAGE 7   

 355   4                              }
 356   3                 }
 357   2                 else
 358   2             {
 359   3                 putstring1("NO ANSWER:\r\n"); 
 360   3                         putstring1(ans); 
 361   3                         putstring1("\r\n"); 
 362   3                         
 363   3                     if((strstr(ans,"RING")) != NULL) return FALSE;
 364   3                 putbyte('\r');
 365   3                 delay_ms(20);
 366   3                     ATSend("AT\r\n");
 367   3                 delay_ms(200);
 368   3                    
 369   3                 }    
 370   2               }
 371   1                
 372   1      }      
 373          
 374          
 375          
 376          
 377          
 378          
 379          
 380          //List all phonebook entries:
 381          // AT+CPBF="DA"
 382          
 383          
 384          
 385          
 386          
 387          
 388          
 389          /************************************************************************************************
 390          *                   int gsmEncode7bit(const char* pSrc, unsigned char* pDst, int nSrcLength) 
 391          * 7-bit编码 
 392          * pSrc: 源字符串指针 
 393          * pDst: 目标编码串指针 
 394          * nSrcLength: 源字符串长度 
 395          * 返回: 目标编码串长度
 396          ***************************************************************************************/
 397          int gsmEncode7bit(char xdata* pSrc, unsigned char xdata* pDst, int nSrcLength) 
 398          {   
 399   1            int xdata nSrc;               // 源字符串的计数值     
 400   1            int xdata nDst;               // 目标编码串的计数值    
 401   1            int xdata nChar;              // 当前正在处理的组内字符字节的序号,范围是0-7   
 402   1            unsigned char xdata nLeft;    // 上一字节残余的数据    
 403   1            // 计数值初始化     
 404   1            nSrc = 0;     
 405   1            nDst = 0;   
 406   1                
 407   1            // 将源串每8个字节分为一组,压缩成7个字节 
 408   1            // 循环该处理过程,直至源串被处理完  
 409   1            // 如果分组不到8字节,也能正确处理  
 410   1            while(nSrc<nSrcLength) 
 411   1            {        
 412   2               // 取源字符串的计数值的最低3位         
 413   2               nChar = nSrc & 7;           
 414   2               
 415   2                       // 处理源串的每个字节      
 416   2               if(nChar == 0)        
C51 COMPILER V7.50   M32                                                                   04/04/2007 15:01:44 PAGE 8   

 417   2               {             
 418   3                 // 组内第一个字节,只是保存起来,待处理下一个字节时使用             
 419   3                 nLeft = *pSrc;         
 420   3               }  
 421   2               else  
 422   2               {             
 423   3                 
 424   3                     // 组内其它字节,将其右边部分与残余数据相加,得到一个目标编码字节             
 425   3                 *pDst = (*pSrc << (8-nChar))| nLeft;             
 426   3                 // 将该字节剩下的左边部分,作为残余数据保存起来             
 427   3                 nLeft = *pSrc >> nChar;       
 428   3                 // 修改目标串的指针和计数值 
 429   3                 pDst++;             
 430   3                         nDst++;          
 431   3               }             
 432   2             
 433   2                   
 434   2                       // 修改源串的指针和计数值         
 435   2               pSrc++; 
 436   2                       nSrc++;  
 437   2            }          
 438   1           
 439   1            // 返回目标串长度     
 440   1            return nDst;  
 441   1      }      
 442          
 443          
 444          // 字节数据转换为可打印字符串 // 如:{0xC8, 0x32, 0x9B, 0xFD, 0x0E, 0x01} --> "C8329BFD0E01"  
 445           // pSrc: 源数据指针 
 446           // pDst: 目标字符串指针 
 447           // nSrcLength: 源数据长度 
 448           // 返回: 目标字符串长度 
 449           int gsmBytes2String(uchar xdata * pSrc, char xdata* pDst, int nSrcLength) 
 450           {     
 451   1              code char tab[]="0123456789ABCDEF";    
 452   1              
 453   1              int i;
 454   1              // 0x0-0xf的字符查找表          
 455   1              for(i=0; i<nSrcLength; i++)     
 456   1              {         
 457   2                      // 输出低4位         
 458   2                      *pDst++ = tab[*pSrc >> 4];   
 459   2                      // 输出高4位         
 460   2                      *pDst++ = tab[*pSrc & 0x0f];              
 461   2                      pSrc++;     
 462   2              }          
 463   1              // 输出字符串加个结束符     
 464   1              *pDst = '\0';          
 465   1              // 返回目标字符串长度     
 466   1              return nSrcLength * 2; 
 467   1       }
 468          
 469          // 可打印字符串转换为字节数据 // 如:"C8329BFD0E01" --> {0xC8, 0x32, 0x9B, 0xFD, 0x0E, 0x01}
 470           // pSrc: 源字符串指针 
 471           // pDst: 目标数据指针 
 472           // nSrcLength: 源字符串长度 
 473           // 返回: 目标数据长度 
 474           //int gsmString2Bytes(const char* pSrc, unsigned char* pDst, int nSrcLength) 
 475           int gsmString2Bytes(uchar* pSrc, uchar* pDst, int nSrcLength) 
 476           {   
 477   1                int i;
 478   1                 
C51 COMPILER V7.50   M32                                                                   04/04/2007 15:01:44 PAGE 9   

 479   1             
 480   1                for(i=0; i<nSrcLength; i+=2)     
 481   1                {         
 482   2                      // 输出高4位         
 483   2                      if((*pSrc>='0') && (*pSrc<='9'))         
 484   2                      {             
 485   3                              *pDst = (*pSrc - '0') << 4;         
 486   3                          
 487   3                      
 488   3                      }         
 489   2                  else         
 490   2                  {             
 491   3                      *pDst = (*pSrc - 'A' + 10) << 4;         
 492   3                  }              
 493   2                                              
 494   2                      
 495   2                      pSrc++;              
 496   2                  // 输出低4位        
 497   2                  if(*pSrc>='0' && *pSrc<='9')         
 498   2                  {             
 499   3                              *pDst  |= (*pSrc - '0');         
 500   3                  }         
 501   2                  else         
 502   2                  {             
 503   3                              *pDst  |= (*pSrc - 'A' + 10);         
 504   3                  }         
 505   2              
 506   2              
 507   2                      
 508   2                      pSrc++;         

⌨️ 快捷键说明

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