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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2966|回復: 1
收起左側

手機短信短信控制繼電器 打電話控制蜂鳴器的單片機源碼

[復制鏈接]
ID:317741 發表于 2018-4-27 14:02 | 顯示全部樓層 |閱讀模式
STC89C52相關程序
0.png

1.短信控制繼電器
2.打電話控制蜂鳴器
3.給目標手機打電話
4.給目標手機發短信

單片機源程序如下:
  1. #include <reg52.h>
  2. #include <intrins.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include "lcd12864.h"

  6. #define uint unsigned int
  7. #define uchar unsigned char

  8. sbit Send_ENGLISH_key=P3^2;     //發英文TEXT短信按鍵
  9. sbit Send_CALLING_key=P3^3;     //打電話按鍵
  10. sbit Send_DS18B20_key=P3^4;     //發溫度按鍵
  11. sbit Send_SMS_PDU_key=P3^5;     //發中文PDU短信按鍵

  12. sbit LED0=P0^0;
  13. sbit LED1=P0^1;
  14. sbit LED2=P0^2;
  15. sbit LED3=P0^3;

  16. #define MAXCHAR 81
  17. uchar  aa[MAXCHAR];

  18. code uchar ATE0[]="ATE0\r\n";
  19. code uchar CREG_CMD[]="AT+CREG?\r\n";
  20. code uchar SMS_send[]="AT+CMGS=18\r\n";
  21. code uchar ATCN[]="AT+CNMI=2,1\r\n";
  22. code uchar CMGF0[]="AT+CMGF=0\r\n";
  23. code uchar CMGF1[]="AT+CMGF=1\r\n";
  24. code uchar CMGR[12]="AT+CMGR=1\r\n";
  25. code uchar CMGD[12]="AT+CMGD=1\r\n";

  26. #define CALL_YOU_TELNUMBER "ATD18622944083;\r\n"    //填入你手上的手機號碼 不是板子的
  27. #define SEND_MESSA_TO_YOUR "at+cmgs=\"18622944083\"\r\n"    //填入你手上的手機號碼 不是板子的
  28. #define SEND_MESSA_CONTENT "tpytongxin.taobao.com"
  29. #define CALL_YOU_TELNUMBER "ATD18622944083;\r\n"    //填入你手上的手機號碼 不是板子的
  30. #define CALL_YOU_TELNUMBER "ATD18622944083;\r\n"    //填入你手上的手機號碼 不是板子的

  31. sbit JIDIANQI=P1^0;

  32. sbit FENGMINGQI=P1^1;



  33. /*-----------------------------------------------------------------------
  34. 1.如果你的晶振是11.0592M
  35. 只需要修改下面的號碼就可以了,給成你手上拿著的手機的號碼


  36. 修改方法   在下面這段字符中找到 5129021411F5

  37. 其實5129021411F5 --> 15922041115
  38. 18622044083 8126924480F3


  39. 看明白了嗎  電話是兩位兩位顛倒 將您手上的手機號碼替換即可
  40. -----------------------------------------------------------------------*/
  41. uchar  code Sms2_Pdu[]="0891683108200205F011000B818126924480F30008A704521B601D";
  42. /*-----------------------------------------------------------------------
  43. 1.如果你的晶振不是11.0592M

  44. 則修改 Ini_UART 函數 波特率 9600


  45. 其他都不用動

  46. -----------------------------------------------------------------------*/

  47. uchar a,j=0,flag=0;
  48. int g_timeout=0;

  49. void delay(uint ms)// 延時子程序
  50. {
  51.     uchar i;
  52.     while(ms--)
  53.     {
  54.         for(i=0;i<120;i++);
  55.     }
  56. }


  57. /***********************************************************
  58. 函數名稱:Print_Char
  59. 函數功能:發送單個字符
  60.           入口參數:ch      出口參數:無
  61. ***********************************************************/
  62. Print_Char(uchar ch)//發送單個字符
  63. {
  64.     SBUF=ch; //送入緩沖區
  65.     while(TI!=1); //等待發送完畢
  66.     TI=0; //軟件清零
  67. }

  68. /***********************************************************
  69. 函數名稱:Print_Str
  70. 函數功能:發送字符串
  71.           入口參數:*str    出口參數:無
  72. ***********************************************************/
  73. Print_Str(uchar *str)//發送字符串
  74. {

  75.     while(*str!='\0')
  76.     {
  77.         Print_Char(*str);
  78.         delay(2);
  79.         str++;
  80.     }

  81. }

  82. /***********************************************************
  83. 函數名稱:Ini_UART
  84. 函數功能:串口初始化、定時器初始化
  85.           入口參數:無     出口參數:無
  86. ***********************************************************/
  87. Ini_UART(void)//串口初始化、定時器初始化
  88. {
  89.     SCON = 0x50 ;  //SCON: serail mode 1, 8-bit UART, enable ucvr
  90.     //UART為模式1,8位數據,允許接收
  91.     TMOD |= 0x20 ; //TMOD: timer 1, mode 2, 8-bit reload
  92.     //定時器1為模式2,8位自動重裝
  93.     PCON |= 0x80 ; //SMOD=1;
  94.     TH1 = 0xFA ;   //Baud:19200 fosc="11".0592MHz
  95.     TL1=0xFA;
  96.     IE |= 0x90 ;     //Enable Serial Interrupt
  97.     TR1 = 1 ;       // timer 1 run
  98.     TI=1;
  99.     ES=1;
  100. }

  101. void clearBuff(void)
  102. {
  103.     for(j=0;j<MAXCHAR;j++)
  104.     {
  105.         aa[j]=0x00;
  106.     }
  107.     j=0;
  108. }

  109. void led(int i)
  110. {
  111.     P2 |= i;
  112.     delay(20);
  113.     P2 &= ~i;
  114.     delay(20);
  115.     P2 |= i;
  116.     delay(20);
  117.     P2 &= ~i;
  118. }

  119. int Hand()
  120. {
  121.     delay(10);
  122.     if(strstr(aa,"OK")!=NULL)             //檢測單片機和模塊的連接
  123.     {
  124.         g_timeout=0;
  125.         return 1;
  126.     }
  127.     if(g_timeout>50)
  128.     {
  129.         g_timeout=0;
  130.         return -1;
  131.     }
  132.     g_timeout++;
  133.     return 0;
  134. }



  135. void AT(void)
  136. {


  137.     clearBuff();
  138.     Print_Str(ATE0);
  139.     delay(50);


  140.     while(strstr(aa,"OK")==NULL)
  141.     {
  142.         delay(50);
  143.         led(0x01);
  144.         v_Lcd12864PutString_f( 1,1, "模塊連接【..】") ;
  145.         clearBuff();
  146.         Print_Str(ATE0);
  147.     }
  148.     led(0x02);

  149.     v_Lcd12864PutString_f( 1,1, "模塊連接【OK】") ;

  150.     Print_Str(ATCN);
  151.     delay(50);


  152.     while(1)
  153.     {
  154.         clearBuff();
  155.         Print_Str(CREG_CMD);
  156.         delay(50);
  157.         if(((aa[9]=='0')&&(aa[11]=='1'))||((aa[9]=='0')&&(aa[11]=='5')))
  158.         {
  159.             clearBuff();
  160.             v_Lcd12864PutString_f( 1,1, "模塊注冊【OK】") ;
  161.             led(0x08);
  162.             break;
  163.         }
  164.         else
  165.         {
  166.             clearBuff();
  167.             v_Lcd12864PutString_f( 1,1, "模塊注冊【..】") ;
  168.             led(0x04);
  169.             delay(50);
  170.         }
  171.     }
  172. }

  173. void send_english()
  174. {
  175.     P2=0XFF;
  176.     clearBuff();

  177.     Print_Str(CMGF1);
  178.     delay(100);
  179.     led(0x01);


  180.     Print_Str(SEND_MESSA_TO_YOUR);

  181.     delay(300);
  182.     led(0x02);

  183.     Print_Str(SEND_MESSA_CONTENT);  //發短信內容
  184.     delay(10);
  185.     Print_Char(0x1A);      //發送結束符號

  186.     delay(10);
  187.     led(0x04);
  188.     clearBuff();
  189. }



  190. void send_call()
  191. {
  192.     clearBuff();
  193.     delay(100);
  194.     Print_Str(CALL_YOU_TELNUMBER); //打電話
  195.     clearBuff();
  196.     delay(300);
  197. }

  198. void send_18B20()
  199. {

  200. }

  201. void send_pdu()
  202. {
  203.     clearBuff();
  204.     Print_Str(CMGF0);
  205.     delay(100);
  206.     led(0x01);

  207.     Print_Str(SMS_send);  //發送中文短信

  208.     delay(500);
  209.     led(0x02);

  210.     Print_Str(Sms2_Pdu);  //發短信內容
  211.     Print_Char(0x1A);      //發送結束符號

  212.     delay(500);
  213.     led(0x04);
  214.     clearBuff();
  215. }


  216. void main()
  217. {

  218.     v_Lcd12864Init_f() ;
  219.     v_Lcd12864PutString_f( 2,0, "") ;
  220.     v_Lcd12864PutString_f( 2,1, "創思通信") ;
  221.     v_Lcd12864PutString_f( 1,2, "") ;
  222.     v_Lcd12864PutString_f( 1,3, "www.csgsm.com") ;

  223.     delay(500);
  224.     Ini_UART();             //初始化串口
  225.     v_Lcd12864PutString_f( 1,1, "串口啟動【OK】") ;

  226.     AT();                   //初始化模塊
  227.     delay(10);


  228.     Send_ENGLISH_key=1;     //發英文TEXT短信按鍵
  229.     Send_CALLING_key=1;     //打電話按鍵
  230.     Send_DS18B20_key=1;     //發溫度按鍵
  231.     Send_SMS_PDU_key=1;     //發中文PDU短信按鍵

  232.     clearBuff();
  233.     Print_Str(CMGD);
  234.     delay(50);
  235.     while(Hand()==0);
  236.     clearBuff();

  237.         Print_Str(CMGF1);
  238.         delay(30);

  239.         Print_Str(ATCN);
  240.         delay(30);



  241.     v_Lcd12864PutString_f( 1,1, "給你電話【..】") ;
  242.     send_call();
  243.     v_Lcd12864PutString_f( 1,1, "給你電話【OK】") ;

  244.     while(1)
  245.     {
  246.         ////////////////////////////////////////////////////////////////////////
  247.         if(Send_ENGLISH_key==0)     //發英文TEXT短信按鍵
  248.         {
  249.             v_Lcd12864PutString_f( 1,1, "英文短信【..】") ;
  250.             send_english();
  251.             v_Lcd12864PutString_f( 1,1, "英文短信【OK】") ;

  252.         }
  253.         else if(Send_CALLING_key==0)     //打電話按鍵
  254.         {
  255.             v_Lcd12864PutString_f( 1,1, "給你電話【..】") ;
  256.             send_call();
  257.             v_Lcd12864PutString_f( 1,1, "給你電話【OK】") ;

  258.         }
  259.         else if(Send_SMS_PDU_key==0)
  260.         {

  261.         }

  262.         ////////////////////////////////////////////////////////////////////////

  263.         //        +CMTI: "SM",1


  264.         if(strstr(aa,"RING")!=NULL)
  265.         {
  266.             FENGMINGQI=0;
  267.             delay(2);
  268.             v_Lcd12864PutString_f( 1,1, "電話來了【親】") ;
  269.             clearBuff();
  270.         }
  271.         else
  272.         {
  273.             FENGMINGQI=1;
  274.         }



  275.         if(strstr(aa,"+CMTI")!=NULL)    //緩存中有+CMTI字符
  276.         {
  277.             clearBuff();
  278.             Print_Str(CMGF1);
  279.             delay(50);
  280.             while(Hand()==0);
  281.             clearBuff();

  282.             Print_Str(CMGR);            //讀取1號位置的短信
  283.             delay(100);


  284.             if(strstr(aa,"k1")!=NULL)
  285.             {
  286.                 v_Lcd12864PutString_f( 1,1, "開繼電器【OK】") ;
  287.                 JIDIANQI=0;
  288.             }
  289.             else if(strstr(aa,"k0")!=NULL)
  290.             {
  291.                 v_Lcd12864PutString_f( 1,1, "關繼電器【OK】") ;
  292.                 JIDIANQI=1;
  293.             }
  294.             else
  295.             {
  296.                 v_Lcd12864PutString_f( 0,3, strstr(aa,",,")) ;
  297.             }

  298.             clearBuff();

  299.             Print_Str(CMGD);
  300.             delay(50);
  301.             while(Hand()==0);
  302.             clearBuff();
  303.         }
  304.         ////////////////////////////////////////////////////////////////////////
  305.     }
  306. }

  307. void ser() interrupt 4
  308. {

  309.     if(RI==1)
  310.     {  aa[j]=SBUF;//命令存到命令數組
  311. ……………………

  312. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
  1. #include <reg52.h>
  2. #include <intrins.h>
  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. sbit Send_SMS_PDU_key=P1^1;     //發PDU格式短信按鍵
  6. sbit LED0=P0^0;
  7. sbit LED1=P0^1;
  8. sbit LED2=P0^2;
  9. sbit LED3=P0^3;

  10. #define MAXCHAR 81
  11. uchar  aa[MAXCHAR];
  12. code uchar ATE0[]="ATE0\r\n";
  13. code uchar CREG_CMD[]="AT+CREG?\r\n";
  14. code uchar SMS_send[]="AT+CMGS=18\r\n";
  15. code uchar ATCN[]="AT+CNMI=2,1\r\n";
  16. code uchar CMGF[]="AT+CMGF=0\r\n";
  17. code uchar CMGR[12]="AT+CMGR=1\r\n";
  18. code uchar CMGD[12]="AT+CMGD=1\r\n";

  19. /*-----------------------------------------------------------------------
  20. 1.如果你的晶振是11.0592M
  21. 只需要修改下面的號碼就可以了,給成你手上拿著的手機的號碼


  22. 修改方法   在下面這段字符中找到 5129021411F5

  23. 其實5129021411F5 --> 15922041115
  24. 18622044083 8126924480F3


  25. 看明白了嗎  電話是兩位兩位顛倒 將您手上的手機號碼替換即可
  26. -----------------------------------------------------------------------*/
  27. uchar  code Sms2_Pdu[]="0891683108200205F011000B818126924480F30008A704521B601D";
  28. /*-----------------------------------------------------------------------
  29. 1.如果你的晶振不是11.0592M

  30. 則修改 Ini_UART 函數 波特率 9600


  31. 其他都不用動

  32. -----------------------------------------------------------------------*/

  33. uchar a,j=0,flag=0;

  34. void delay(uint ms)// 延時子程序
  35. {
  36.     uchar i;
  37.     while(ms--)
  38.     {
  39.         for(i=0;i<120;i++);
  40.     }
  41. }


  42. /***********************************************************
  43. 函數名稱:Print_Char
  44. 函數功能:發送單個字符
  45.           入口參數:ch      出口參數:無
  46. ***********************************************************/
  47. Print_Char(uchar ch)//發送單個字符
  48. {
  49.     SBUF=ch; //送入緩沖區
  50.     while(TI!=1); //等待發送完畢
  51.     TI=0; //軟件清零
  52. }

  53. /***********************************************************
  54. 函數名稱:Print_Str
  55. 函數功能:發送字符串
  56.           入口參數:*str    出口參數:無
  57. ***********************************************************/
  58. Print_Str(uchar *str)//發送字符串
  59. {

  60.     while(*str!='\0')
  61.     {
  62.         Print_Char(*str);
  63.         delay(2);
  64.         str++;
  65.     }

  66. }

  67. /***********************************************************
  68. 函數名稱:Ini_UART
  69. 函數功能:串口初始化、定時器初始化
  70.           入口參數:無     出口參數:無
  71. ***********************************************************/
  72. Ini_UART(void)//串口初始化、定時器初始化
  73. {
  74.     SCON = 0x50 ;  //SCON: serail mode 1, 8-bit UART, enable ucvr
  75.     //UART為模式1,8位數據,允許接收
  76.     TMOD |= 0x20 ; //TMOD: timer 1, mode 2, 8-bit reload
  77.     //定時器1為模式2,8位自動重裝
  78.     PCON |= 0x80 ; //SMOD=1;
  79.     TH1 = 0xFA ;   //Baud:19200 fosc="11".0592MHz
  80.     TL1=0xFA;
  81.     IE |= 0x90 ;     //Enable Serial Interrupt
  82.     TR1 = 1 ;       // timer 1 run
  83.     TI=1;
  84.     ES=1;
  85. }

  86. void clearBuff(void)
  87. {
  88.     for(j=0;j<MAXCHAR;j++)
  89.     {
  90.         aa[j]=0x00;
  91.     }
  92.     j=0;
  93. }

  94. void led(int i)
  95. {
  96.     P2 |= i;
  97.     delay(20);
  98.     P2 &= ~i;
  99.     delay(20);
  100.     P2 |= i;
  101.     delay(20);
  102.     P2 &= ~i;
  103. }



  104. void AT(void)
  105. {

  106.     while(1)
  107.     {
  108.         Print_Str(ATE0);
  109.         delay(50);

  110.         Print_Str(ATCN);
  111.         delay(50);

  112.         Print_Str(CMGF);
  113.         delay(100);

  114.         clearBuff();
  115.         Print_Str(CREG_CMD);
  116.         delay(50);


  117.         if(((aa[9]=='0')&&(aa[11]=='1'))||((aa[9]=='0')&&(aa[11]=='5')))
  118.         {
  119.             clearBuff();
  120.             led(0x02);
  121.             break;
  122.         }
  123.         else
  124.         {
  125.             clearBuff();

  126.             led(0x01);
  127.             delay(50);
  128.         }
  129.     }
  130. }


  131. void main()
  132. {

  133.     Ini_UART();    //初始化串口
  134.     AT();                   //初始化模塊
  135.     delay(10);

  136.     Print_Str(SMS_send);  //發送中文短信
  137.     delay(500);
  138.     led(0x04);

  139.     Print_Str(Sms2_Pdu);  //發短信內容
  140.     delay(500);
  141.     led(0x08);

  142.     Print_Char(0x1A);      //發送結束符號
  143.         delay(500);

  144.         Print_Str("ATD18622944083;\r\n"); //打電話

  145.     while(1);
  146. }

  147. void ser() interrupt 4
  148. {



  149.     if(RI==1)
  150.     {  aa[j]=SBUF;//命令存到命令數組

  151.         RI=0; //軟件清除接收中斷
  152.         j++;
  153.     }


  154. }
復制代碼


所有資料51hei提供下載:
STC89C52程序.zip (2.82 MB, 下載次數: 59)


回復

使用道具 舉報

ID:288689 發表于 2019-3-25 13:25 來自手機 | 顯示全部樓層
請問一下你這個設計硬件部分是什么樣的啊
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美日韩不卡合集视频 | 一级免费毛片 | 日韩高清三区 | 欧美久久一区 | 在线一区视频 | 一区二区三区欧美 | 国产成人一区二 | 亚洲一区 | 中文字幕视频在线观看免费 | 日韩一区二区三区四区五区 | 欧美男人亚洲天堂 | 久草在线 | 精品亚洲91 | 国产精品高潮呻吟久久aⅴ码 | 91社区在线观看高清 | 久久99国产精品久久99果冻传媒 | 天天射中文 | 国产在线视频一区二区董小宛性色 | 精品久久久久久久久久久久久久 | 日本粉嫩一区二区三区视频 | 国产午夜影院 | 99精品久久99久久久久 | 精品一区二区电影 | 日韩精品 电影一区 亚洲 | 久久久久久久久久久久亚洲 | 国产精品揄拍一区二区 | 国产国拍亚洲精品av | 天天做日日做 | 超碰在线97国产 | 国产激情视频在线观看 | 性高湖久久久久久久久3小时 | 久久久久久亚洲精品 | 免费a国产 | 亚洲欧美中文日韩在线v日本 | 自拍 亚洲 欧美 老师 丝袜 | 日韩亚洲一区二区 | 精品一区二区三区中文字幕 | 成人精品一区亚洲午夜久久久 | 伊人免费视频二 | 日韩一区在线播放 | 91综合在线观看 |