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

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 23646|回復(fù): 44
收起左側(cè)

A6 GPRS+GSM模塊51單片機(jī)TCP通信及發(fā)送短信實(shí)例程序

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

A6模塊接線方式:
1.準(zhǔn)備一個(gè)STC89C52最小系統(tǒng)板

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

單片機(jī)源程序如下:
  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;       //定時(shí)器計(jì)數(shù)器

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

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

  15. unsigned int count = 0;
  16.        

  17. //****************************************************
  18. //主函數(shù)
  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.                 //發(fā)送數(shù)據(jù)
  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);                 //發(fā)送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. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼

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


相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

ID:205579 發(fā)表于 2017-5-28 11:09 | 顯示全部樓層
恢復(fù)加點(diǎn)積分
回復(fù)

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

ID:216190 發(fā)表于 2017-6-30 21:17 | 顯示全部樓層
頭文件不對(duì)勁啊,不能編譯啊
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).
回復(fù)

使用道具 舉報(bào)

ID:218440 發(fā)表于 2017-7-10 10:57 | 顯示全部樓層
學(xué)習(xí)了!!!!!!
回復(fù)

使用道具 舉報(bào)

ID:223229 發(fā)表于 2017-7-29 16:21 | 顯示全部樓層
分?jǐn)?shù)不夠怎么辦啊?想下載看看
回復(fù)

使用道具 舉報(bào)

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

使用道具 舉報(bào)

ID:230838 發(fā)表于 2017-9-5 10:58 | 顯示全部樓層
入門級(jí)
回復(fù)

使用道具 舉報(bào)

ID:240764 發(fā)表于 2017-10-18 22:01 來自手機(jī) | 顯示全部樓層
很有用,喜歡
回復(fù)

使用道具 舉報(bào)

ID:152966 發(fā)表于 2017-10-30 13:42 | 顯示全部樓層
能不能加點(diǎn)分
回復(fù)

使用道具 舉報(bào)

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

使用道具 舉報(bào)

ID:250494 發(fā)表于 2017-11-17 17:46 | 顯示全部樓層
非常有用
回復(fù)

使用道具 舉報(bào)

ID:147616 發(fā)表于 2017-11-26 17:21 | 顯示全部樓層
看看 學(xué)習(xí)一下
回復(fù)

使用道具 舉報(bào)

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

使用道具 舉報(bào)

ID:179958 發(fā)表于 2017-12-7 20:13 來自手機(jī) | 顯示全部樓層
謝謝樓主無(wú)私分享,學(xué)習(xí)學(xué)習(xí)
回復(fù)

使用道具 舉報(bào)

ID:269114 發(fā)表于 2017-12-30 10:21 | 顯示全部樓層
分?jǐn)?shù)不夠
回復(fù)

使用道具 舉報(bào)

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

他這個(gè)少了一個(gè)頭文件,51單片機(jī)的沒有定義頭文件
回復(fù)

使用道具 舉報(bào)

ID:303817 發(fā)表于 2018-4-8 17:07 | 顯示全部樓層
看看 學(xué)習(xí)一下
回復(fù)

使用道具 舉報(bào)

ID:311938 發(fā)表于 2018-4-19 19:56 | 顯示全部樓層
學(xué)習(xí)學(xué)習(xí)
回復(fù)

使用道具 舉報(bào)

ID:311938 發(fā)表于 2018-4-19 21:51 | 顯示全部樓層
漲知識(shí)了
回復(fù)

使用道具 舉報(bào)

ID:323997 發(fā)表于 2018-5-7 11:41 | 顯示全部樓層
學(xué)習(xí)一下謝謝大神
回復(fù)

使用道具 舉報(bào)

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

使用道具 舉報(bào)

ID:335878 發(fā)表于 2018-5-22 18:14 來自手機(jī) | 顯示全部樓層
學(xué)習(xí)了!!!!
回復(fù)

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

ID:374540 發(fā)表于 2018-7-19 09:07 | 顯示全部樓層
gsm模塊加單片機(jī) 很好的應(yīng)用
回復(fù)

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

ID:391540 發(fā)表于 2018-8-30 11:38 | 顯示全部樓層
想看下接入網(wǎng)絡(luò)部分的代碼.
回復(fù)

使用道具 舉報(bào)

ID:388878 發(fā)表于 2018-9-5 16:25 | 顯示全部樓層
STC89C52 GPRS TCP通信
回復(fù)

使用道具 舉報(bào)

ID:380103 發(fā)表于 2018-12-2 20:52 | 顯示全部樓層
你好,這個(gè)接線直接三根不行啊,能告訴一下我怎么接么
回復(fù)

使用道具 舉報(bào)

ID:486582 發(fā)表于 2019-3-7 21:55 | 顯示全部樓層
所有的GPRS模塊都是通用的嗎
回復(fù)

使用道具 舉報(bào)

ID:423119 發(fā)表于 2019-3-15 21:33 | 顯示全部樓層
我好想下載,但是沒有積分
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 欧美日韩视频网站 | 欧美日韩亚洲国产 | 国产成人高清成人av片在线看 | 中文一区二区 | 亚洲精品乱| 欧美日韩国产一区二区三区 | 日日摸天天添天天添破 | 亚洲精品一区国语对白 | av在线一区二区三区 | 欧美成人免费在线 | 欧美在线视频a | 韩日在线| 亚洲成人自拍 | 在线中文字幕视频 | 精品一区视频 | 欧美一区二区三区在线 | 久久夜色精品国产 | 日韩视频精品在线 | 久久精品亚洲国产奇米99 | 亚洲 欧美 另类 综合 偷拍 | 久久av.com | 日韩欧美二区 | 日韩欧美高清dvd碟片 | 久久一区视频 | 亚洲国产成人av好男人在线观看 | 欧美一区永久视频免费观看 | 精品欧美一区二区三区久久久 | 国产精品大片在线观看 | 精品国产一区二区国模嫣然 | 在线观看中文字幕dvd播放 | 国产特黄一级 | 久久久久久久电影 | 久久精品一 | 色免费在线视频 | 最新国产精品精品视频 | 日本黄色免费视频 | 国产精品视频网 | 日韩精品一区二区久久 | 国产成人精品久久二区二区91 | 四虎影院在线播放 | 久久精品国产久精国产 |