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

標題: A6 GPRS+GSM模塊51單片機TCP通信及發送短信實例程序 [打印本頁]

作者: Eanain    時間: 2017-5-24 20:38
標題: 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)



作者: rongwinzip    時間: 2017-5-28 11:09
恢復加點積分
作者: hiya    時間: 2017-5-31 14:14
好想下載啊
作者: 1130555300    時間: 2017-5-31 21:31
有沒有電路圖?
作者: zxy2266    時間: 2017-6-13 23:02
現在研究GPRS可惜沒有黑幣
作者: 909169697    時間: 2017-6-30 19:46
樓主在不在啊
作者: 909169697    時間: 2017-6-30 19:47
樓主在不啊,審核好麻煩
作者: 909169697    時間: 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).
作者: 15728001162    時間: 2017-7-10 10:57
學習了。。。。!
作者: heeyon    時間: 2017-7-29 16:21
分數不夠怎么辦?想下載看看
作者: 非黃騰達    時間: 2017-8-17 17:54
壓縮包的程序和直接給的程序都不一樣,很懷疑樓主是怎么使用的????
作者: 敲代碼時間    時間: 2017-9-5 10:58
入門級
作者: zjw12694    時間: 2017-10-18 22:01
很有用,喜歡
作者: ryanycy    時間: 2017-10-30 13:42
能不能加點分
作者: ryanycy    時間: 2017-10-30 13:42
試試看
作者: qweqwertyuiop    時間: 2017-11-17 17:46
非常有用
作者: 2100598336    時間: 2017-11-26 17:21
看看 學習一下
作者: 袁潔棟    時間: 2017-12-7 19:11
謝謝分享,下載了
作者: 小潘哥    時間: 2017-12-7 20:13
謝謝樓主無私分享,學習學習
作者: 852200    時間: 2017-12-30 10:21
分數不夠
作者: 1126469277    時間: 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單片機的沒有定義頭文件
作者: 幾許輕唱    時間: 2018-4-8 17:07
看看 學習一下
作者: DoveMyZ    時間: 2018-4-19 19:56
學習學習
作者: DoveMyZ    時間: 2018-4-19 21:51
漲知識了
作者: haikuc    時間: 2018-5-7 11:41
學習一下謝謝大神
作者: xxd123456    時間: 2018-5-22 17:41
下載了是哪一個呢???

作者: 笑看    時間: 2018-5-22 18:14
學習了。。!
作者: fish_yu    時間: 2018-6-27 21:15
很想看一下,可惜沒有黑幣
作者: 滄瀾釣翁    時間: 2018-7-1 08:20
謝謝樓主分享,很棒!!
作者: 李志康的    時間: 2018-7-2 15:23
想下載看看  就是沒黑幣
作者: 兩航。    時間: 2018-7-19 09:07
gsm模塊加單片機 很好的應用
作者: yuanhaidong    時間: 2018-7-21 21:05
謝謝樓主分享
作者: yuanhaidong    時間: 2018-7-21 21:05
感謝樓主分享,蹭個熱度。很好用
作者: m123    時間: 2018-8-28 20:26
感謝分享。。。。。。。。
作者: a965718891    時間: 2018-8-29 11:07
謝謝大佬們,,,
作者: xiaogua    時間: 2018-8-30 11:38
想看下接入網絡部分的代碼.
作者: brcsss    時間: 2018-9-5 16:25
STC89C52 GPRS TCP通信
作者: 奇虎楠夏    時間: 2018-12-2 20:52
你好,這個接線直接三根不行啊,能告訴一下我怎么接么
作者: G_5748    時間: 2019-3-7 21:55
所有的GPRS模塊都是通用的嗎
作者: songkdksljf    時間: 2019-3-15 21:33
我好想下載,但是沒有積分
作者: 山高水遠啊    時間: 2019-3-30 16:07
厲害                        
作者: 罪惡王冠    時間: 2019-4-5 17:36
還不錯把,就是有些難懂。
作者: xxxdcr    時間: 2019-7-4 16:13
這個是真的寫得很不錯,結構清晰明了,內容簡單易懂,適合我這種學板子新手
作者: wx1831    時間: 2019-7-6 15:09
可以   
作者: 守護00    時間: 2019-7-14 19:29
我試了為什么沒有用




歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1