久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2411|回復: 0
打印 上一主題 下一主題
收起左側

GSM短信模塊AT指令及編程

[復制鏈接]
跳轉到指定樓層
樓主
ID:130758 發表于 2016-7-17 10:48 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
單片機串口不夠用或者沒有串口,怎么樣模擬呢?
串口通信時數據格式由一個起始位,八個數據位,一個或兩個結束位組成。在數據發送是結束位是不能省。但在數據接收時,程序中就沒有必要等待結束位了,因為在等待結束位的過程中,把下一個數據的起始中斷也等待過去了。程序發送口采用任一IO口,接收口采用外部中斷0口,實現了9600bit/s的串口通信,信號產生與接收采用定時器定時溢出標志來進行控制。另外在程序中需要注意下面問題:1、中斷的中斷標志要保證狀態正確2、定時器定時要精確  下面是我們單片機是所寫的串口通信程序,主要用來實習發送和接收短信,因此下面的AT指令讓我們一起學習一下:
AT指令功能
  AT+CMGC Send an SMS commend(發出一條短信息命令)
  AT+CMGD Delete SMS message (刪除SIM卡內存的信息)
  AT+CMGF Select SMS message format(選擇短消息信息格式:0-PDU;1-文本)
  AT+CMGL List SMS message from preferred store(列出SIM卡中的短消息格式PDU/TEXT:0“REC
  UNREAD”為未讀,1“REC READ”為已讀,2“STOU NSENT”為待發,3“STOSENT”為已發,
  4“ALL”為全部
  AT+CMGR Read SMS message (讀短消息)
  AT+CMGS Send SMS message (發短消息)
  AT+CMGW Write SMS message to memory (向SIM內存中寫入待發的短消息)
  AT+CNMI New SMS message storage(顯示新收到的短消息)
  AT+CPMS Preferred SMS message storage (選擇短消息內存)
  AT+CSCA SMS service center address(短消息中心地址)
  AT+CSCB Select cell broadcast message messages (選擇蜂窩廣播信息)
  AT+CSMP Set SMS text mode parameters(設置短消息文本模式參數)
  模塊的供電電壓如果低于3.3V會自動關機。同時模塊在在發射時,電流峰值可高達2A。同時在此電流峰值時,電源電壓(送入模塊的電壓)下降值不能超過0.4V。所以該模塊對電源的要求較高,電源的內阻+FFC聯接線的電阻必需小于200mΩ。
  單片機通過兩根I/O口控制TC35的開關機、復位等,通過串口與TC35進行數據通信,通信速率為9600Kbps,采用8位異步通訊方式,1位起始位,8位數據位,1位停止位。
TC35模塊輸入輸出的TTL正電平邏輯不是+5V,而是+2.9V,因此必要時加端口保護。
#ifndef sentmessage
#define    sentmessage
#define  uint   unsigned   int
#define  uchar   unsigned   char
void delay_1000us(uchar n)        //延遲0.01s         
{
    unsignedchar a,b,c;
       for(c=0;c<n;c++)
       {
           for(b=249;b>0;b--)
          for(a=17;a>0;a--);
       }
}      
void delay_100us(uchar c)   //誤差 -0.173611111111us
{
   unsigned char a,b,i;
       for(i=0;i<c;i++)
       {
           for(b=1;b>0;b--)
               for(a=43;a>0;a--);
       }
}
voiddelay_5s(void)   //誤差 -0.000000002274us
{
   unsigned char a,b,c;
   for(c=203;c>0;c--)
       for(b=156;b>0;b--)
           for(a=144;a>0;a--);
}
void Sendchar(unsigned char c)
{
   SBUF = c;
   while(!TI);
   TI = 0;
}
void Sentstring(unsigned char *p)
{
       while(*p!='\0')
       {
         Sendchar(*p++);
    }
}
/*
void Sent_message()
{  

       Sentstring("AT+CMGS=\"1252015215029882\"");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);

       Sentstring("afasfasd");
       delay_100us(60);
       Sendchar(0x1a);
}
*/
void Pre_readmessage()
{  
   Sentstring("AT");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);

       Sentstring("AT+CMGF=1");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);

       Sentstring("AT+CNMI=2,1");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
}
void Readmessage(unsigned char msgnum) //讀短信
{   
   ES=1;
       Sentstring("AT+CMGR=");
       Sendchar(msgnum);
       Sendchar(0X0D);
       Sendchar(0X0A);     
      delay_1000us(300);
       ES=0;                                   
}
void Delete_message(uchar num)
{  
      Sentstring("AT+CMGD=");
       Sendchar(num);
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
}

void Send_yfhz(uchar str[])
{
       Sentstring("AT");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGF=0");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGS=23");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("0891683108408705F0");    //發送內容
       Sentstring("11000D9168");
       Sentstring(str);
       Sentstring("000801086CE8610F9632706B");   
       Sendchar(0x1a);
       delay_1000us(500);
}//0891683108200305F011000D91683146384837F2000801084E3B4EBA8BF7610F6CE8
//0891683108200309F011000D91685121333639F7000801064E3B4EBA8BF7610F6CE8
void Send_bxg(uchar str[])
{
       Sentstring("AT");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGF=0");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGS=23");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("0891683108408705F0");    //發送內容
       Sentstring("11000D9168");
       Sentstring(str);
       Sentstring("000801086CE8610F963276D7");   
       Sendchar(0x1a);
       delay_1000us(500);
}
void Send_tdg(uchar str[])
{
       Sentstring("AT");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGF=0");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGS=23");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("0891683108408705F0");    //發送內容
       Sentstring("11000D9168");
       Sentstring(str);
       Sentstring("0008010853F0706F5DF25173");   
       Sendchar(0x1a);
       delay_1000us(500);
}
void Send_secret(uchar str[])
{
       Sentstring("AT");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGF=0");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGS=23");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("0891683108408705F0");    //發送內容
       Sentstring("11000D9168");
       Sentstring(str);
       Sentstring("0008010895E8670953719669");   
       Sendchar(0x1a);     
       delay_1000us(500);
}
void Send_tdk(uchar str[])
{
       Sentstring("AT");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGF=0");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGS=23");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("0891683108408705F0");    //發送內容
       Sentstring("11000D9168");
       Sentstring(str);
       Sentstring("0008010853F0706F5DF25F00");   
       Sendchar(0x1a);     
       delay_1000us(500);
}
  /*
void Send_tdk1()
{

       Sentstring("AT");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGF=0");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGS=23");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(30);
       Sentstring("0891683108408705F0");    //發送內容
       Sentstring("11000D91685112059288F2");
       Sentstring("0008010853F0706F5DF25F00");  
       Sendchar(0x1a);     
       delay_1000us(500);
}*/
void Send_fsg(uchar str[])
{
       Sentstring("AT");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGF=0");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGS=23");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("0891683108408705F0");    //發送內容
       Sentstring("11000D9168");
       Sentstring(str);
       Sentstring("0008010898CE62475DF25173");   
       Sendchar(0x1a);
       delay_1000us(500);
}
void Send_fsk(uchar str[])
{
       Sentstring("AT");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGF=0");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGS=23");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("0891683108408705F0");    //發送內容
       Sentstring("11000D9168");
       Sentstring(str);
       Sentstring("0008010898CE62475DF25F00");   
       Sendchar(0x1a);
       delay_1000us(500);
}
void Send_ykm(uchar str[])
{
       Sentstring("AT");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGF=0");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGS=23");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("0891683108408705F0");    //發送內容
       Sentstring("11000D9168");
       Sentstring(str);
       Sentstring("000801085DF262535F0095E8");   
       Sendchar(0x1a);
       delay_1000us(500);
}
void Send_jiankong(uchar str[],uint a,uintb)
{     
       Sentstring("AT");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGF=1");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("AT+CMGS=");
       Sentstring(str);
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("taideng shi ");
       if(a==1)
         Sentstring("guan de,");
       else
         Sentstring("kai de,");
       Sentstring("fengshan shi ");
          if(b==1)
         Sentstring("guan de!");
       else
         Sentstring("kai de!");
       Sendchar(0X0D);
       Sendchar(0X0A);
       Sendchar(0x1a);
       delay_1000us(500);
}
void Send_phone(uchar str[])
{

       Sentstring("AT");
       Sendchar(0X0D);
       Sendchar(0X0A);
       delay_1000us(20);
       Sentstring("atd");
       Sentstring(str);
       Sentstring(";");
       Sendchar(0X0D);
       Sendchar(0X0A);   
       delay_1000us(500);        
}
#endif

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产精品一区二区三区久久久 | 99国内精品久久久久久久 | 色综合色综合网色综合 | 情侣酒店偷拍一区二区在线播放 | 日韩伦理一区二区 | 中国一级特黄真人毛片免费观看 | 91网在线观看 | 超碰免费在线 | 亚洲精品中文字幕在线观看 | 亚洲视频免费观看 | 黄色一级大片视频 | 在线国产一区 | 一级黄色片网站 | 精品日韩一区二区三区 | 亚洲日本欧美 | 国产高清在线视频 | 理伦毛片 | 久久久精品视 | 亚洲第一视频网 | 中文字幕第二区 | 国产玖玖| 日韩中文字幕一区二区 | 久草视频在线播放 | 一区二区视频 | 国产精品免费一区二区三区四区 | 五月婷婷亚洲 | 国产激情99 | 二区三区av| 欧美成人精品一区二区男人看 | 久久日韩精品一区二区三区 | 精品一区电影 | 国产欧美日韩视频 | 欧美激情啪啪 | wwwxxx国产| 欧美精品久久久久久 | 日本不卡一区二区三区在线观看 | 国产激情福利 | 日韩欧美网 | 国产精品久久一区二区三区 | 九九热精品视频在线观看 | 久久久一|