当前位置: 代码迷 >> Windows Mobile >> 如何用at指令发短信
  详细解决方案

如何用at指令发短信

热度:126   发布时间:2016-04-25 07:54:05.0
怎么用at指令发短信?
请给出代码



------解决方案--------------------
最近在做这方面的课设,刚写的代码,不过因为是要烧进单片机的,片子还没回来,所以没有调试过。。。。
大家也帮忙看看有没有问题吧:)
C/C++ code
void sendMessage(){    sendAT();    sendBPS();    setPDUmode();    sendLength();    sendContent();}void sendText(){    while(sendBuffer[sendPointer] != '\0')    {        sendASC(sendBuffer[sendPointer ++]);    }    clearSendBuffer();}void sendAT(){    while(1)    {        sendASC('A');        sendASC('T');        sendASC(0x1A);        ES = 0;        delay(50);        clearReadBuffer();        p = strstr(readBuffer, "OK");        if(p != NULL)            break;    }    }void sendBPS(){    strcpy(sendBuffer, "AT+IPR=19200");    sendText();}void setPDUmode(){    while(1)    {        strcpy(sendBuffer, "AT+CMFG=2");        sendText();        ES = 0;        delay(50);        clearReadBuffer();        p = strstr(readBuffer, "OK");        if(p != NULL)            break;    }}void sendLength(){    while(1)    {        strcpy(sendBuffer, "AT+CMGS=26");        sendText();        ES = 0;        delay(50);        clearReadBuffer();        p = strstr(readBuffer, '>');        if(p != NULL)            break;    }}void sendContent(){    strcpy(sendBuffer, "0891683108705505F011000D91683104176226F00008000A67094EBA76D78F66FF01");//PDU编码内容    sendText();    sendASC(0x1A);}void sendASC(uchar ASC){    SBUF = ASC;}void delay(uchar i){    while(i --){}    }void clearSendBuffer(){    while(sendPointer >= 0)    {        sendBuffer[sendPointer --] = 0;    }    sendPointer = 0;}void clearReadBuffer(){    while(readPointer >= 0)    {        readBuffer[readPointer --] = 0;    }    readPointer = 0;}
  相关解决方案