找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 6157|回復(fù): 7
打印 上一主題 下一主題
收起左側(cè)

sim300用51單片機(jī)發(fā)短信的程序代碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:98984 發(fā)表于 2015-12-9 14:22 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
哪位有sim300用51單片機(jī)發(fā)短信的程序代碼


  1. /************************************************************
  2. 程序說明:
  3. 本程序?qū)崿F(xiàn)發(fā)送一條英文短信,向10086 這個號碼發(fā)送103這個指令
  4. 1.我們的程序全部都是通過單片機(jī)串口2與SIM300通訊,串口1用于下載程序和觀察SIM300返回的數(shù)據(jù)
  5. (串口2收到的SIM300返回的數(shù)據(jù)會通過串口1發(fā)送到電腦中,用于觀察數(shù)據(jù)),使用過程中,如果沒
  6. 有特殊要求跳線帽不用變動。
  7. 2.在開發(fā)板上放入您的手機(jī)卡,接好天線,打開電源,接入耳機(jī)。
  8. 3.把程序編譯后下載到單片機(jī)中,使用STC—ISP下載,具體請參照教程。

  9. 4.按下按鍵4發(fā)送指令查詢當(dāng)前服務(wù)狀態(tài),當(dāng)服務(wù)狀態(tài)顯示CHINA MOBILE 則證明找到網(wǎng)絡(luò),可以正常通
  10. 訊了,如果顯示0,0,再按下按鍵4,等到出現(xiàn)CHINA MOBILE為止
  11. 5.按下按鍵5發(fā)送指令設(shè)置10086電話是短信發(fā)送的號碼
  12. 6.此時串口會回復(fù) '>'
  13. 6.按下按鍵6設(shè)置發(fā)送內(nèi)容,發(fā)送短信,成功后串口返回+CMGS ..


  14. *************************************************************/

  15. #include "stc12c5a.h"
  16. #include "systerm.h"
  17. #include "gprs.h"
  18. #include "timer.h"



  19. void main()
  20. {

  21. //  調(diào)整輸入函數(shù)的加載值可以改變串口波特率
  22. //        Uart1Init(0,1,184);//初始化串口,設(shè)置波特率4800
  23. //        Uart2Init(0,1,220);//初始化串口,設(shè)置波特率9600
  24. //        Uart2Init(0,1,232);//初始化串口,設(shè)置波特率14400
  25. //        Uart1Init(0,1,253);//初始化串口,設(shè)置波特率115200


  26.         Timer0Init();
  27.         Uart1Init(0,1,220);//初始化串口,設(shè)置波特率9600
  28.         Uart2Init(0,1,220);//初始化串口,設(shè)置波特率9600


  29. //啟動Sim300要按下復(fù)位鍵大概3秒鐘
  30.         GPRS_RST = 0;//Sim300 復(fù)位鍵拉低
  31.         DelaySec(3);//延時3秒
  32.         GPRS_RST = 1;//Sim300 復(fù)位鍵拉高
  33.         //Sim300啟動完成

  34.         LED5_OFF;
  35.         LED6_OFF;
  36.         LED7_OFF;
  37.         LED8_OFF;
  38.        
  39.         while(1)
  40.         {
  41.                 if(KEY4_PRESS)//按鍵4發(fā)送指令查詢當(dāng)前服務(wù)狀態(tài)
  42.                 {
  43.                         while(KEY4_PRESS)
  44.                         {
  45.                                 LED8_ON;       
  46.                         }
  47.                         LED8_OFF;
  48.                         Uart2Sends("at+cops?\r");//發(fā)送指令查詢當(dāng)前服務(wù)狀態(tài)                               
  49.                 }

  50.                 if(KEY5_PRESS)//按鍵5發(fā)送指令發(fā)送10086電話號碼
  51.                 {
  52.                         while(KEY5_PRESS)
  53.                         {
  54.                                 LED7_ON;       
  55.                         }
  56.                         LED7_OFF;
  57.                         Uart2Sends("AT+CMGF=1\r");//設(shè)置英文方式發(fā)送,當(dāng)然也可以用中文的AT+CMGF=0,不過發(fā)送方式不太一樣,具體請看相關(guān)程序
  58.                         DelaySec(1);
  59.                         Uart2Sends("AT+CMGS=\"10086\"\r");//發(fā)送指令設(shè)置10086電話是短信發(fā)送的號碼
  60.                                
  61.                 }

  62.                 if(KEY6_PRESS)//按鍵6發(fā)送內(nèi)容
  63.                 {
  64.                         while(KEY6_PRESS)
  65.                         {
  66.                                 LED6_ON;       
  67.                         }
  68.                         LED6_OFF;
  69.                         Uart2Sends("103");//103 為發(fā)送的內(nèi)容
  70.                         Uart2Send(0x1a);//以0x1a來結(jié)束,表示內(nèi)容結(jié)束,發(fā)送短信                               
  71.                 }

  72.         }
  73.        
  74. }

復(fù)制代碼



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

使用道具 舉報

沙發(fā)
ID:1 發(fā)表于 2015-12-9 16:49 | 只看該作者


SIM300 GPRS單片機(jī)源程序.rar (131.81 KB, 下載次數(shù): 55)


  1. /**************************************************************************
  2. *                                                                        *
  3. *                                         SIM300實現(xiàn)電話呼叫和GPRS                              *
  4. *                                                                        *
  5. * 功能:實現(xiàn)任意的電話呼叫(號碼從鍵盤輸入)                               *
  6. *       實現(xiàn)呼入電話的接聽                                               *
  7. *                 實現(xiàn)GPRS連接和發(fā)送固定的GPRS信息                                 *
  8. * 版本: V1.0 (2010/07/23)                                               *
  9. * 網(wǎng)站:                            *
  10. * 郵箱: hificat@163.com                                                 *
  11. * 來源: 杭州晶控電子有限公司  HANGZHOU KinCony ELECTRONICS CO.,LTD      *
  12. *【版權(quán)】Copyright(C) 杭州晶控電子 www.hificat.com  All Rights Reserved  *
  13. *【聲明】此程序僅用于學(xué)習(xí)與參考,引用請注明版權(quán)和作者信息!              *
  14. *                                                                        *
  15. *************************************************************************/
  16. #include <SIM300.h>
  17. //#include <reg51.h>
  18. #include <string.h>

  19. unsigned char q=0;
  20. unsigned char count=0;

  21. unsigned char number[15];//"13185077790";
  22. unsigned char num=0;

  23. void main(void)
  24. {
  25.         sys_init();
  26.         BELL_UP();        
  27.         LCD_init();
  28.         LCD_clear();
  29.         start();
  30.         Start_GSM();

  31.         GSM_init();
  32.         clear_SystemBuf();
  33.         while(strsearch("Call Ready",SystemBuf)==0);
  34.         BELL_UP();
  35.         do
  36.         {
  37.                 LCD_clear();
  38.                 clear_SystemBuf();
  39.                 sendstring(AT_COPS);
  40.                 LCD_write_english_string( 4,2,"searching>");
  41.                 Delay_ms(3000);
  42.                 LCD_write_english_string( 4,2,"searching->");
  43.                 Delay_ms(3000);
  44.                 LCD_write_english_string( 4,2,"searching-->");
  45.                 Delay_ms(3000);
  46.                 LCD_write_english_string( 4,2,"searching--->");
  47.                 Delay_ms(3000);
  48.         }while((strsearch("MOBILE",SystemBuf)==0)&&(strsearch("UNICOM",SystemBuf)==0));//檢測服務(wù)商信息
  49.         
  50.         BELL_UP();
  51.         LCD_clear();
  52.         if(strsearch("MOBILE",SystemBuf)!=0)LCD_write_chinese_string(16,2,12,4,6,0);//顯示服務(wù)商??
  53.         if(strsearch("UNICOM",SystemBuf)!=0)LCD_write_chinese_string(16,2,12,4,10,0);//顯示服務(wù)商??
  54.         LCD_write_english_string(0,0,"KinCony");
  55.         ET0=1;  //T0 中斷
  56.         for(num=0;num<15;num++)
  57.         {
  58.                 number[num]=0;
  59.         }num=0;
  60.         while(1)
  61.         {
  62.                 do
  63.                 {
  64.                         scan();
  65.                         if(strsearch("RING",SystemBuf)!=0)
  66.                         {
  67.                                 clear_SystemBuf();
  68.                                 LCD_write_english_string(0,5,"CALL<---------");
  69.                                 do
  70.                                 {        
  71.                                         ET0=0;
  72.                                         BELL_UP();
  73.                                         if(scan()==12)
  74.                                         {
  75.                                                 sendstring(ATA);
  76.                                                 LCD_write_english_string(0,5,"              ");
  77.                                                 LCD_write_english_string(0,5,"connet call...");
  78.                                                 break;
  79.                                         }
  80.                                 }while((scan()!=14)&&(strsearch("NO CARRIER",SystemBuf)==0));
  81.                                 clear_SystemBuf();
  82.                                 LCD_write_english_string(0,5,"              ");
  83.                                 ET0=1;
  84.                         }
  85.                 }
  86.                 while(jump==0);
  87.                 LCD_set_XY(count,5);
  88.                 if ((scan()>=0)&&(scan()<=9)||scan()==-6||scan()==-13) //數(shù)字鍵
  89.                 {
  90.                         if(count<84)
  91.                         count+=6;
  92.                         LCD_write_char(scan()+48);
  93.                         number[num]=scan()+0x30;
  94.                         num++;
  95.                 }
  96.                 else if(scan()==12)//退格鍵
  97.                 {
  98.                         if(count>0)
  99.                         {
  100.                                 count-=6;
  101.                                 num--;
  102.                                 number[num]=0;
  103.                                 LCD_set_XY(count,5);
  104.                                 LCD_write_char(32);
  105.                                 LCD_set_XY(count,5);
  106.                         }
  107.                 }
  108.                 else if(scan()==15)//撥號鍵
  109.                 {
  110.                         unsigned char call[20]="ATD";
  111.                         strcat(call,number);//13185077790
  112.                         strcat(call,";");
  113.                         sendstring(call);
  114.                         clear_SystemBuf();
  115.                         ET0=0;
  116.                         while(1)
  117.                         {
  118.                                 LCD_write_english_string(0,5,"CALL--------->");
  119.                                 if(scan()==14) //掛機(jī)鍵
  120.                                 {
  121.                                         sendstring(ATH);
  122.                                         for(num=0;num<15;num++)
  123.                                         {
  124.                                                 number[num]=0;
  125.                                         }
  126.                                         num=0;
  127.                                         LCD_write_english_string(0,5,"              ");
  128.                                         count=0;
  129.                                         ET0=1;
  130.                                         break;
  131.                                 }
  132.                         }
  133.                 }
  134.                 else if(scan()==14) //掛機(jī)鍵
  135.                 {
  136.                         sendstring(ATH);
  137.                         for(num=0;num<15;num++)
  138.                         {
  139.                                 number[num]=0;
  140.                         }
  141.                         num=0;
  142.                         LCD_write_english_string(0,5,"              ");
  143.                         count=0;
  144.                 }
  145.                 else if(scan()==13)//GPRS演示程序(gprs連接一次發(fā)送消息然后斷開)
  146.                 {
  147.                         ET0=0;
  148.                         sendstring(AT_CIPCLOSE);Delay_ms(5000);        
  149.                         sendstring(AT_CIPSHUT); Delay_ms(5000);        
  150.                         sendstring(AT_CDSNORIP);Delay_ms(5000);        
  151.                         sendstring(AT_CIPHEAD); Delay_ms(5000);        
  152.                         sendstring(AT_CIPSTART);
  153.                         Delay_ms(5000);        
  154.                         Delay_ms(5000);
  155.                          LCD_write_english_string(0,5,"              ");
  156.                         LCD_write_english_string(0,5,"connet gprs...");
  157.                         Delay_ms(5000);        
  158.                         Delay_ms(5000);
  159.                         LCD_write_english_string(0,5,"              ");
  160.                         LCD_write_english_string(0,5,"gprs ok!      ");
  161.                         sendstring(AT_CIPSEND);
  162.                         Delay_ms(5000);        
  163.                         Delay_ms(5000);        
  164.                         sendstring("Welcome to HANGZHOU KinCony ELECTRONICS!");
  165.                         Delay_ms(5000);        
  166.                         Delay_ms(5000);        
  167.                         LCD_write_english_string(0,5,"              ");
  168.                         LCD_write_english_string(0,5,"gprs sending..");
  169.                         sendchar(0x1a);
  170.                         Delay_ms(5000);        
  171.                         Delay_ms(5000);        
  172.                         LCD_write_english_string(0,5,"              ");
  173.                         LCD_write_english_string(0,5,"gprs send ok  ");
  174.                         Delay_ms(5000);        
  175.                         Delay_ms(5000);        
  176.                         LCD_write_english_string(0,5,"              ");
  177.                         sendstring(AT_CIPCLOSE);Delay_ms(5000);        
  178.                         sendstring(AT_CIPSHUT); Delay_ms(5000);
  179.                         ET0=1;
  180.                 }
  181.                 delayms(800);delayms(800);delayms(800);
  182.                 jump=0;
  183.         }
  184. }
  185. /********************************************************************************************************
  186. ** 函數(shù)名稱         Int_Timer0()
  187. ** 函數(shù)功能                定時器中斷位,是整個程序的心跳,如果停止,程序會死機(jī)
  188. *********************************************************************************************************/
  189. void  Int_Timer0(void) interrupt 1 using 3
  190. {
  191.         TH0 = 0xB8;
  192.         TL0 = 0x00;                                         //20ms的時鐘基準(zhǔn)
  193.         timer_1S_cnt++;   
  194.         timercount++;
  195.         
  196.         if(timer_1S_cnt==50)                    //20×50=1000M
  197.         {
  198.                 timer_10S_cnt++;
  199.                 timer_1S_cnt=0;
  200.                 timer_S_cnt++;
  201.                 LED_S0=~LED_S0;        
  202.                 Signal();
  203.         }                                      //1秒=1000毫秒
  204.         if(timer_10S_cnt==60)                   //60S
  205.         {
  206.                 timer_10S_cnt=0;
  207.                
  208.         }
  209. }
復(fù)制代碼
回復(fù)

使用道具 舉報

板凳
ID:1 發(fā)表于 2015-12-9 17:00 | 只看該作者
基于sim300和51單片機(jī)實現(xiàn)遠(yuǎn)程短信內(nèi)容識別控制和數(shù)據(jù)采集,可用于報警等事件觸發(fā)場合.rar (22.03 KB, 下載次數(shù): 57)
SIM300模塊51單片機(jī)控制發(fā)送一條英文短信.rar (61.64 KB, 下載次數(shù): 51)

評分

參與人數(shù) 1黑幣 +5 收起 理由
zqy1818 + 5 很給力!

查看全部評分

回復(fù)

使用道具 舉報

地板
ID:109173 發(fā)表于 2016-3-16 15:30 | 只看該作者
單片機(jī)+GPRS
回復(fù)

使用道具 舉報

5#
ID:199240 發(fā)表于 2017-5-10 19:29 | 只看該作者
能不能摸以提定的手機(jī)號碼發(fā)短信高價也行?
回復(fù)

使用道具 舉報

6#
ID:263579 發(fā)表于 2017-12-20 16:02 | 只看該作者
此程序可以用于800A嗎?
回復(fù)

使用道具 舉報

7#
ID:306434 發(fā)表于 2018-4-12 10:44 | 只看該作者
感謝分享!
回復(fù)

使用道具 舉報

8#
ID:58591 發(fā)表于 2018-8-4 11:30 | 只看該作者
感謝分享,支持下
回復(fù)

使用道具 舉報

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

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表