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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

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

  [復制鏈接]
跳轉到指定樓層
樓主

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)


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

使用道具 舉報

沙發
ID:205579 發表于 2017-5-28 11:09 | 只看該作者
恢復加點積分
回復

使用道具 舉報

板凳
ID:206349 發表于 2017-5-31 14:14 | 只看該作者
好想下載啊
回復

使用道具 舉報

地板
ID:157662 發表于 2017-5-31 21:31 | 只看該作者
有沒有電路圖?
回復

使用道具 舉報

5#
ID:198286 發表于 2017-6-13 23:02 | 只看該作者
現在研究GPRS可惜沒有黑幣
回復

使用道具 舉報

6#
ID:216190 發表于 2017-6-30 19:46 | 只看該作者
樓主在不在啊
回復

使用道具 舉報

7#
ID:216190 發表于 2017-6-30 19:47 | 只看該作者
樓主在不啊,審核好麻煩
回復

使用道具 舉報

8#
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).
回復

使用道具 舉報

9#
ID:218440 發表于 2017-7-10 10:57 | 只看該作者
學習了!!!!!!
回復

使用道具 舉報

10#
ID:223229 發表于 2017-7-29 16:21 | 只看該作者
分數不夠怎么辦啊?想下載看看
回復

使用道具 舉報

11#
ID:183779 發表于 2017-8-17 17:54 | 只看該作者
壓縮包的程序和直接給的程序都不一樣,很懷疑樓主是怎么使用的????
回復

使用道具 舉報

12#
ID:230838 發表于 2017-9-5 10:58 | 只看該作者
入門級
回復

使用道具 舉報

13#
ID:240764 發表于 2017-10-18 22:01 來自手機 | 只看該作者
很有用,喜歡
回復

使用道具 舉報

14#
ID:152966 發表于 2017-10-30 13:42 | 只看該作者
能不能加點分
回復

使用道具 舉報

15#
ID:152966 發表于 2017-10-30 13:42 | 只看該作者
試試看
回復

使用道具 舉報

16#
ID:250494 發表于 2017-11-17 17:46 | 只看該作者
非常有用
回復

使用道具 舉報

17#
ID:147616 發表于 2017-11-26 17:21 | 只看該作者
看看 學習一下
回復

使用道具 舉報

18#
ID:64178 發表于 2017-12-7 19:11 | 只看該作者
謝謝分享,下載了
回復

使用道具 舉報

19#
ID:179958 發表于 2017-12-7 20:13 來自手機 | 只看該作者
謝謝樓主無私分享,學習學習
回復

使用道具 舉報

20#
ID:269114 發表于 2017-12-30 10:21 | 只看該作者
分數不夠
回復

使用道具 舉報

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單片機的沒有定義頭文件
回復

使用道具 舉報

22#
ID:303817 發表于 2018-4-8 17:07 | 只看該作者
看看 學習一下
回復

使用道具 舉報

23#
ID:311938 發表于 2018-4-19 19:56 | 只看該作者
學習學習
回復

使用道具 舉報

24#
ID:311938 發表于 2018-4-19 21:51 | 只看該作者
漲知識了
回復

使用道具 舉報

25#
ID:323997 發表于 2018-5-7 11:41 | 只看該作者
學習一下謝謝大神
回復

使用道具 舉報

26#
ID:335755 發表于 2018-5-22 17:41 | 只看該作者
下載了是哪一個呢???
回復

使用道具 舉報

27#
ID:335878 發表于 2018-5-22 18:14 來自手機 | 只看該作者
學習了!!!!
回復

使用道具 舉報

28#
ID:252143 發表于 2018-6-27 21:15 | 只看該作者
很想看一下,可惜沒有黑幣
回復

使用道具 舉報

29#
ID:279195 發表于 2018-7-1 08:20 | 只看該作者
謝謝樓主分享,很棒!!!
回復

使用道具 舉報

30#
ID:363029 發表于 2018-7-2 15:23 | 只看該作者
想下載看看  就是沒黑幣
回復

使用道具 舉報

31#
ID:374540 發表于 2018-7-19 09:07 | 只看該作者
gsm模塊加單片機 很好的應用
回復

使用道具 舉報

32#
ID:202314 發表于 2018-7-21 21:05 | 只看該作者
謝謝樓主分享
回復

使用道具 舉報

33#
ID:202314 發表于 2018-7-21 21:05 | 只看該作者
感謝樓主分享,蹭個熱度。很好用
回復

使用道具 舉報

34#
ID:390948 發表于 2018-8-28 20:26 | 只看該作者
感謝分享。。。。。。。。
回復

使用道具 舉報

35#
ID:303722 發表于 2018-8-29 11:07 | 只看該作者
謝謝大佬們,,,
回復

使用道具 舉報

36#
ID:391540 發表于 2018-8-30 11:38 | 只看該作者
想看下接入網絡部分的代碼.
回復

使用道具 舉報

37#
ID:388878 發表于 2018-9-5 16:25 | 只看該作者
STC89C52 GPRS TCP通信
回復

使用道具 舉報

38#
ID:380103 發表于 2018-12-2 20:52 | 只看該作者
你好,這個接線直接三根不行啊,能告訴一下我怎么接么
回復

使用道具 舉報

39#
ID:486582 發表于 2019-3-7 21:55 | 只看該作者
所有的GPRS模塊都是通用的嗎
回復

使用道具 舉報

40#
ID:423119 發表于 2019-3-15 21:33 | 只看該作者
我好想下載,但是沒有積分
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久夜色精品国产 | 蜜臀久久| 亚洲国产欧美一区二区三区久久 | 婷婷国产一区 | 国产在线观看福利 | 亚洲电影一级片 | 久久三区 | 欧美黄色片 | 中文字幕精品一区久久久久 | 美女黄视频网站 | 欧美色综合网 | 日本精品一区二区三区在线观看视频 | 亚洲综合视频一区 | 黄 色 毛片免费 | 成年人在线视频 | 国产高清一二三区 | 一区二区电影网 | 一区二区三区日韩精品 | 亚洲欧洲一区二区 | 国产成人免费观看 | 亚洲国产成人av好男人在线观看 | 久久伊人青青草 | 在线免费观看视频你懂的 | 婷婷久| 欧美另类日韩 | 91传媒在线观看 | 久久精品国产亚洲a | 国产精品久久av | 美女激情av | www.五月婷婷.com | 日韩在线小视频 | 中国美女撒尿txxxxx视频 | 国产视频中文字幕 | 国产精品日韩在线观看 | 久久青 | 精品久久成人 | 久久在视频 | 欧美一级二级三级 | 91精品国产91久久久久游泳池 | 国产免费观看视频 | 欧美福利久久 |