欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 23936|回復: 44
收起左側

A6 GPRS+GSM模塊51單片機TCP通信及發送短信實例程序

  [復制鏈接]
ID:204446 發表于 2017-5-24 20:38 | 顯示全部樓層 |閱讀模式
QQ圖片20170524203742.png
01.STC89C52撥打電話
02.STC89C52發送英文短信
03.STC89C52 GPRS TCP通信
04.STC15W GPS解析

A6模塊接線方式:
1.準備一個STC89C52最小系統板

2.燒錄代碼(先燒錄代碼后接線,防止接線后下載不了代碼)
3.給模塊供電,給模塊開機
4.接線:
    STC89C52        A6&A7
    GND        ->        GND
    TXD/P3.1->        U_RXD
    RXD/P3.0->        U_TXD

單片機源程序如下:
  1. /*********************************************************************
  2.                  作者:神秘藏寶室
  3. *********************************************************************/

  4. #include "main.h"
  5. #include "uart.h"

  6. //常量
  7. #define Success 1U
  8. #define Failure 0U

  9. //定義變量
  10. unsigned long  Time_Cont = 0;       //定時器計數器

  11. code char phoneNumber[] = "17719228082";                //替換成需要被撥打電話的號碼
  12. code char msg[] = "ILoveMCU.taobao.com";                //短信內容

  13. code char TCPServer[] = "122.228.19.57";                //TCP服務器地址
  14. code char Port[] = "30396";                                                //端口

  15. unsigned int count = 0;
  16.        

  17. //****************************************************
  18. //主函數
  19. //****************************************************
  20. void main()
  21. {
  22.     Uart_Init();

  23.         if (sendCommand("AT+RST\r\n", "OK\r\n", 3000, 10) == Success);
  24.         else errorLog();
  25.         delay_ms(10);

  26.         if (sendCommand("AT\r\n", "OK\r\n", 3000, 10) == Success);
  27.         else errorLog();
  28.         delay_ms(10);

  29.         if (sendCommand("AT+CPIN?\r\n", "READY", 1000, 10) == Success);
  30.         else errorLog();
  31.         delay_ms(10);

  32.         if (sendCommand("AT+CREG?\r\n", "CREG: 1", 1000, 10) == Success);
  33.         else errorLog();
  34.         delay_ms(10);

  35.         if (sendCommand("AT+CGATT=1\r\n", "OK\r\n", 1000, 10) == Success);
  36.         else errorLog();
  37.         delay_ms(10);

  38.         if (sendCommand("AT+CGDCONT=1,\"IP\",\"CMNET\"\r\n", "OK\r\n", 1000, 10) == Success);
  39.         else errorLog();
  40.         delay_ms(10);


  41.         if (sendCommand("AT+CGACT=1,1\r\n","OK\r\n", 1000, 10) == Success);
  42.         else errorLog();
  43.         delay_ms(10);

  44.        

  45.         while(1)
  46.         {       
  47.                  char xdata send_buf[100] = {0};
  48.                 memset(send_buf, 0, 100);    //清空
  49.                 strcpy(send_buf, "AT+CIPSTART=\"TCP\",\"");
  50.                 strcat(send_buf, TCPServer);
  51.                 strcat(send_buf, "\",");
  52.                 strcat(send_buf, Port);
  53.                 strcat(send_buf, "\r\n");
  54.                 if (sendCommand(send_buf, "CONNECT", 10000, 5) == Success);
  55.                 else errorLog();

  56.                 //發送數據
  57.                 if (sendCommand("AT+CIPSEND\r\n", ">", 3000, 5) == Success);
  58.                 else errorLog();

  59.                 memset(send_buf, 0, 100);    //清空
  60.                 sprintf(send_buf,"ILoveMCU.taobao.com %d\r\n",count);
  61.                 count++;
  62.                

  63.                 if (sendCommand(send_buf, send_buf, 3000, 1) == Success);
  64.                 else errorLog();
  65.                 delay_ms(100);

  66.                 memset(send_buf, 0, 100);    //清空
  67.                 send_buf[0] = 0x1a;
  68.                 if (sendCommand(send_buf, send_buf, 3000, 5) == Success);
  69.                 else errorLog();
  70.                 delay_ms(100);

  71.                 if (sendCommand("AT+CIPCLOSE\r\n", "OK\r\n", 3000, 10) == Success);
  72.                 else errorLog();

  73.                 delay_ms(1000);
  74.         }
  75. }

  76. void sendMessage(char *number,char *msg)
  77. {
  78.         xdata char send_buf[20] = {0};
  79.         memset(send_buf, 0, 20);    //清空
  80.         strcpy(send_buf, "AT+CMGS=\"");
  81.         strcat(send_buf, number);
  82.         strcat(send_buf, "\"\r\n");
  83.         if (sendCommand(send_buf, ">", 3000, 10) == Success);
  84.         else errorLog();

  85.         SendString(msg);

  86.         SendData(0x1A);
  87. }

  88. void phone(char *number)
  89. {
  90.         char send_buf[20] = {0};
  91.         memset(send_buf, 0, 20);    //清空
  92.         strcpy(send_buf, "ATD");
  93.         strcat(send_buf, number);
  94.         strcat(send_buf, ";\r\n");

  95.         if (sendCommand(send_buf, "SOUNDER", 10000, 10) == Success);
  96.         else errorLog();
  97. }

  98. void errorLog()
  99. {
  100.         while (1)
  101.         {
  102.                   if (sendCommand("AT\r\n", "OK", 100, 10) == Success)
  103.                 {
  104.                         soft_reset();
  105.                 }
  106.                 delay_ms(200);
  107.         }
  108. }

  109. void soft_reset(void)         //制造重啟命令
  110. {
  111.    ((void (code *) (void)) 0x0000) ();
  112. }

  113. unsigned int sendCommand(char *Command, char *Response, unsigned long Timeout, unsigned char Retry)
  114. {
  115.         unsigned char n;
  116.         CLR_Buf();
  117.         for (n = 0; n < Retry; n++)
  118.         {
  119.                 SendString(Command);                 //發送GPRS指令

  120.                 Time_Cont = 0;
  121.                 while (Time_Cont < Timeout)
  122.                 {
  123.                         delay_ms(100);
  124.                         Time_Cont += 100;
  125.                         if (strstr(Rec_Buf, Response) != NULL)
  126.                         {
  127. ……………………

  128. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
6.51單片機例程.rar (298.3 KB, 下載次數: 511)


回復

使用道具 舉報

ID:205579 發表于 2017-5-28 11:09 | 顯示全部樓層
恢復加點積分
回復

使用道具 舉報

ID:206349 發表于 2017-5-31 14:14 | 顯示全部樓層
好想下載啊
回復

使用道具 舉報

ID:157662 發表于 2017-5-31 21:31 | 顯示全部樓層
有沒有電路圖?
回復

使用道具 舉報

ID:198286 發表于 2017-6-13 23:02 | 顯示全部樓層
現在研究GPRS可惜沒有黑幣
回復

使用道具 舉報

ID:216190 發表于 2017-6-30 19:46 | 顯示全部樓層
樓主在不在啊
回復

使用道具 舉報

ID:216190 發表于 2017-6-30 19:47 | 顯示全部樓層
樓主在不啊,審核好麻煩
回復

使用道具 舉報

ID:216190 發表于 2017-6-30 21:17 | 顯示全部樓層
頭文件不對勁啊,不能編譯啊
compiling gsmC.c...
gsmC.c(18): warning C318: can't open file 'main.h'
gsmC.c(19): warning C318: can't open file 'uart.h'
GSMC.C(37): warning C206: 'Uart_Init': missing function-prototype
GSMC.C(39): warning C206: 'sendCommand': missing function-prototype
GSMC.C(39): error C267: 'sendCommand': requires ANSI-style prototype
gsmC.c - 1 Error(s), 4 Warning(s).
回復

使用道具 舉報

ID:218440 發表于 2017-7-10 10:57 | 顯示全部樓層
學習了!!!!!!
回復

使用道具 舉報

ID:223229 發表于 2017-7-29 16:21 | 顯示全部樓層
分數不夠怎么辦啊?想下載看看
回復

使用道具 舉報

ID:183779 發表于 2017-8-17 17:54 | 顯示全部樓層
壓縮包的程序和直接給的程序都不一樣,很懷疑樓主是怎么使用的????
回復

使用道具 舉報

ID:230838 發表于 2017-9-5 10:58 | 顯示全部樓層
入門級
回復

使用道具 舉報

ID:240764 發表于 2017-10-18 22:01 來自觸屏版 | 顯示全部樓層
很有用,喜歡
回復

使用道具 舉報

ID:152966 發表于 2017-10-30 13:42 | 顯示全部樓層
能不能加點分
回復

使用道具 舉報

ID:152966 發表于 2017-10-30 13:42 | 顯示全部樓層
試試看
回復

使用道具 舉報

16#
無效樓層,該帖已經被刪除
ID:250494 發表于 2017-11-17 17:46 | 顯示全部樓層
非常有用
回復

使用道具 舉報

ID:147616 發表于 2017-11-26 17:21 | 顯示全部樓層
看看 學習一下
回復

使用道具 舉報

ID:64178 發表于 2017-12-7 19:11 | 顯示全部樓層
謝謝分享,下載了
回復

使用道具 舉報

ID:179958 發表于 2017-12-7 20:13 來自觸屏版 | 顯示全部樓層
謝謝樓主無私分享,學習學習
回復

使用道具 舉報

ID:269114 發表于 2017-12-30 10:21 | 顯示全部樓層
分數不夠
回復

使用道具 舉報

ID:242941 發表于 2018-2-8 11:53 | 顯示全部樓層
909169697 發表于 2017-6-30 21:17
頭文件不對勁啊,不能編譯啊
compiling gsmC.c...
gsmC.c(18): warning C318: can't open file 'main.h'
...

他這個少了一個頭文件,51單片機的沒有定義頭文件
回復

使用道具 舉報

ID:303817 發表于 2018-4-8 17:07 | 顯示全部樓層
看看 學習一下
回復

使用道具 舉報

24#
無效樓層,該帖已經被刪除
ID:311938 發表于 2018-4-19 19:56 | 顯示全部樓層
學習學習
回復

使用道具 舉報

ID:311938 發表于 2018-4-19 21:51 | 顯示全部樓層
漲知識了
回復

使用道具 舉報

ID:323997 發表于 2018-5-7 11:41 | 顯示全部樓層
學習一下謝謝大神
回復

使用道具 舉報

ID:335755 發表于 2018-5-22 17:41 | 顯示全部樓層
下載了是哪一個呢???
回復

使用道具 舉報

ID:335878 發表于 2018-5-22 18:14 來自觸屏版 | 顯示全部樓層
學習了!!!!
回復

使用道具 舉報

ID:252143 發表于 2018-6-27 21:15 | 顯示全部樓層
很想看一下,可惜沒有黑幣
回復

使用道具 舉報

ID:279195 發表于 2018-7-1 08:20 | 顯示全部樓層
謝謝樓主分享,很棒!!!
回復

使用道具 舉報

ID:363029 發表于 2018-7-2 15:23 | 顯示全部樓層
想下載看看  就是沒黑幣
回復

使用道具 舉報

ID:374540 發表于 2018-7-19 09:07 | 顯示全部樓層
gsm模塊加單片機 很好的應用
回復

使用道具 舉報

ID:202314 發表于 2018-7-21 21:05 | 顯示全部樓層
謝謝樓主分享
回復

使用道具 舉報

ID:202314 發表于 2018-7-21 21:05 | 顯示全部樓層
感謝樓主分享,蹭個熱度。很好用
回復

使用道具 舉報

ID:390948 發表于 2018-8-28 20:26 | 顯示全部樓層
感謝分享。。。。。。。。
回復

使用道具 舉報

ID:303722 發表于 2018-8-29 11:07 | 顯示全部樓層
謝謝大佬們,,,
回復

使用道具 舉報

ID:391540 發表于 2018-8-30 11:38 | 顯示全部樓層
想看下接入網絡部分的代碼.
回復

使用道具 舉報

39#
無效樓層,該帖已經被刪除
ID:388878 發表于 2018-9-5 16:25 | 顯示全部樓層
STC89C52 GPRS TCP通信
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表