⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smsdrive.lst

📁 51单片机控制TC35模块的程序
💻 LST
📖 第 1 页 / 共 4 页
字号:
C51 COMPILER V7.08   SMSDRIVE                                                              04/12/2010 21:34:57 PAGE 1   


C51 COMPILER V7.08, COMPILATION OF MODULE SMSDRIVE
OBJECT MODULE PLACED IN smsDrive.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE smsDrive.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <reg51.h>
   2          #include <intrins.h>
   3          #include <string.h>
   4          #include <stdio.h>              //一般IO/函数
   5          #include <ctype.h>
   6          #define U8 unsigned char
   7          #define U16 unsigned int
   8          #define MAX_TM   265
   9          #define MAX_T  35
  10          #define LED P0
  11          sbit spk=P0^3;
  12          
  13          sbit led2=P1^1;
  14          sbit IO_OUT=P1^0;
  15          //◇◇◇◇◇◇◇◇◇◇定义接收中断相关变量        
  16          U8 xdata rec[512];
  17          U8 count=0;
  18          bit flag=0;
  19          bit ReceiveFlag=0;
  20          bit sendflag;
  21          U8 idata TEL_temp[15];
  22          U8 data para_temp[512];
  23          //△△△△△△△△△△定义接收中断相关变量
  24          
  25          //---定时用-----------
  26          U16  data timercount;           //50MS定时器,
  27          U8 data timer_1S_cnt;
  28          U8 data timer_10S_cnt;
  29          U8 data timer_S_cnt;
  30          //--------------------
  31          
  32          //◇◇◇◇◇◇◇◇◇◇定义有权发送短信的用户    
  33          U8 code SendUser1[]="13633634914F";
  34          U8 code SendUser2[]="13633634914F";
  35          U8 code order1[]="asd";
  36          //△△△△△△△△△△定义有权发送短信的用户
  37          
  38          
  39          U8 code Content_rule[] = {
  40          0xCC,0xF4,0x19,0x4D,0x07,0xBD,0xDD
  41          } ;          //Light on
  42          
  43          
  44          U8 code Command_At[3] = "AT\r";
  45          /*发送:41 54 0d 
  46          接收到:41 54 0D 0D 0A 4F 4B 0D 0A
  47          对应字符:
  48          AT<CR>
  49          OK
  50          */ 
  51          
  52          U8 code Command_Csq[7] = "AT+CSQ\r";         //Signal quality test
  53          /*发送:41 54 2B 43 53 51 0d
  54          接收到:41 54 2B 43 53 51 0D 0D 0A 2B 43 53 51 3A 20 33 31 2C 39 39 0D 0A 0D 0A 4F 4B 0D 0A 
  55          对应字符:
C51 COMPILER V7.08   SMSDRIVE                                                              04/12/2010 21:34:57 PAGE 2   

  56          AT+CSQ<CR>
  57          +CSQ: 31,99
  58          
  59          OK
  60          */
  61          /////////////////////////////////////////
  62          U8 code Command_CPIN[9] = "AT+CPIN?\r";
  63          U8 code Command_COPS[9] = "AT+COPS?\r";
  64          U8 code Command_ATE1[6] = "ATE1\r";         //Signal quality test
  65          U8 code Command_ATV1[6] = "ATV1\r";
  66          ///////////////////////////////////////         //Signal quality test
  67          
  68          U8 code Command_Cmgf1[10] = "AT+CMGF=1\r";      
  69                                                    //选择短消息信息格式,设置为文本模式。若 "AT+CMGF=0\r",设置为PDU
             - 模式
  70          /*发送:41 54 2B 43 4D 47 46 3D 31 0D
  71          接收到:41 54 2B 43 4D 47 46 3D 31 0D 0D 0A 4F 4B 0D 0A
  72          对应字符:
  73          AT+CMGF=1<CR>
  74          OK
  75          */
  76          
  77          U8 code Command_Cscs[12] = "AT+CSCS=GSM\r";       //设置为GSM 字符集
  78          /*发送:41 54 2B 43 53 43 53 3D 47 53 4D 0D
  79          接收到:41 54 2B 43 53 43 53 3D 47 53 4D 0D 0D 0A 4F 4B 0D 0A
  80          对应字符:
  81          AT+CSCS=GSM<CR>
  82          OK
  83          */
  84          
  85          U8 code Command_Cnmi[12] = "AT+CNMI=2,1\r";       //设置新短信提示
  86          /*发送:41 54 2B 43 4E 4D 49 3D 32 2C 31 0D
  87          接收到:41 54 2B 43 4E 4D 49 3D 32 2C 31 0D 0D 0A 4F 4B 0D 0A 
  88          对应字符:
  89          AT+CNMI=2,1<CR>
  90          OK
  91          */
  92          
  93          U8 data Command_Cmgr[10] = "AT+CMGR=1\r";         //读取短消息
  94          /*发送:41 54 2B 43 4D 47 52 3D */
  95          
  96          U8 data Command_Cmgd[10] = "AT+CMGD=1\r";         //删除短消息
  97          /*发送:41 54 2B 43 4D 47 44 3D */
  98          
  99          U8 code Command_CmgsT1[20] = "AT+CMGS=13633634914\r";     //给用户1 发送文本短消息
 100          /*发送:41 54 2B 43 4D 47 53 3D 31 33 34 38 35 33 34 34 36 33 34 0D
 101          接收到:41 54 2B 43 4D 47 53 3D 31 33 32 33 33 36 34 37 31 34 33 0D 0D 0A 3E 20
 102          对应字符:
 103          AT+CMGS=13233647143<CR>
 104          ><SP>
 105          */
 106          
 107          U8 code Command_CmgsT2[20] = "AT+CMGS=13633634914\r";     //给用户2 发送文本短消息
 108          /*发送:41 54 2B 43 4D 47 53 3D 31 33 32 33 33 36 34 37 31 34 33 0D
 109          接收到:41 54 2B 43 4D 47 53 3D 31 33 32 33 33 36 34 37 31 34 33 0D 0D 0A 3E 20
 110          对应字符:
 111          AT+CMGS=13233647143<CR>
 112          ><SP>
 113          */
 114          
 115          
 116          /*===========================================
C51 COMPILER V7.08   SMSDRIVE                                                              04/12/2010 21:34:57 PAGE 3   

 117          *函数名:ms级延时 子函数
 118          *参   数:
 119          *功   能:
 120          *返回值:
 121          *作  者:weishao2401  2009/4/29
 122          *============================================*/
 123          
 124          void DelayMs(U8 ms)
 125          {                                               
 126   1           U8 i;
 127   1           while(ms--)
 128   1           {
 129   2             for(i = 0; i < 120; i++);
 130   2           }
 131   1      }
 132          ////////////////////////////////////////////////////////////////
 133          void  Int_Timer0(void) interrupt 1 using 3
 134          {
 135   1           TH0 = 0xB8;
 136   1               TL0 = 0x00; //20ms的时钟基准
 137   1      
 138   1         timer_1S_cnt++;   timercount++;
 139   1         if(timer_1S_cnt==50)    //20×50=1000MS  =1S
 140   1          { timer_10S_cnt++; timer_1S_cnt=0;
 141   2            timer_S_cnt++;
 142   2                //LED_S0=~LED_S0;
 143   2      
 144   2          }                              //1秒=1000毫秒
 145   1          if(timer_10S_cnt==60)   //60S
 146   1          {
 147   2                 timer_10S_cnt=0;
 148   2      
 149   2              }
 150   1      
 151   1      //---------------------------------------------------------------------------------
 152   1      
 153   1      }
 154          ////////////////////////////////////////////////////
 155          /*===========================================
 156          *函数名:TC35正确提示 子函数
 157          *参   数:
 158          *功   能:2声长响
 159          *返回值:
 160          *作  者:weishao2401  2009/4/29
 161          *============================================*/
 162          
 163          void deal_with_right(void)
 164          {   
 165   1           U8 i;      
 166   1           for(i=0;i<2;i++)
 167   1           {
 168   2              DelayMs (60);
 169   2              spk=0;    //开启扬声器 让蜂鸣器工作
 170   2              DelayMs (60);
 171   2              spk=1;
 172   2           }
 173   1      }
 174          
 175          /*===========================================
 176          *函数名:TC35发送命令提示 子函数
 177          *参   数:
 178          *功   能:1声短响
C51 COMPILER V7.08   SMSDRIVE                                                              04/12/2010 21:34:57 PAGE 4   

 179          *返回值:
 180          *作  者:weishao2401  2009/4/29
 181          *============================================*/
 182          
 183          void deal_with_attention(void)
 184          {   
 185   1           U8 i;      
 186   1           for(i=0;i<1;i++)
 187   1           {
 188   2              DelayMs (40);
 189   2              spk=0;    //开启扬声器 让蜂鸣器工作
 190   2              DelayMs (40);
 191   2              spk=1;
 192   2           }
 193   1      }
 194          
 195          
 196          /*===========================================
 197          *函数名:TC35出错处理 子函数
 198          *参   数:
 199          *功   能:5声短响
 200          *返回值:
 201          *作  者:weishao2401  2009/4/29
 202          *============================================*/
 203          
 204          void deal_with_error(void)
 205          {   
 206   1           U8 i;      
 207   1           for(i=0;i<5;i++)
 208   1           {
 209   2              DelayMs (30);
 210   2              spk=0;    //开启扬声器 让蜂鸣器工作
 211   2              DelayMs (30);
 212   2              spk=1;
 213   2           }
 214   1      }
 215          
 216          
 217          
 218          
 219          /*===========================================
 220          *函数名:串口初始化 子函数
 221          *参   数:
 222          *功   能:
 223          *返回值:
 224          *作  者:weishao2401  2009/4/29
 225          *============================================*/
 226          
 227          void UART_Init(void)
 228           {   TI=0; RI=0;
 229   1           SCON|=0x50;  /* mode 1: 8-bit UART, enable receiver */ 
 230   1           TMOD|=0x21; /* timer 1 mode 2: 8-Bit reload */ 
 231   1           PCON|=0x80; // baud x2 
 232   1           TH1=0xfa;     //串口波特率初始化 0xfd=19200,0xfa=9600
 233   1           ES=1;           //打开串行中断
 234   1           TR1=1;         //打开定时器1
 235   1      /////////////////////////////////////////
 236   1          TH0 = 0xB8;
 237   1              TL0 = 0x00; //20ms的时钟基准
 238   1          TR0=1; //串口接收中断
 239   1          ET0=1;  //T0 中断
 240   1          EA=1;
C51 COMPILER V7.08   SMSDRIVE                                                              04/12/2010 21:34:57 PAGE 5   

 241   1          P0=0xff;
 242   1          P1=0xff;
 243   1          P2=0xff;
 244   1          P3=0xff;
 245   1          timer_1S_cnt=0;
 246   1          
 247   1      ///////////////////////
 248   1       }
 249           
 250           
 251          /*===========================================
 252          *函数名:串口发送 子函数
 253          *参   数:U8 data_buffer[], U8 data_len
 254          *功   能:
 255          *返回值:
 256          *作  者:weishao2401  2009/4/29
 257          *============================================*/
 258          
 259          void uart_send(U8 data_buffer[],U8 data_len)
 260          {
 261   1        U8 i;
 262   1        ES=0;  
 263   1        TI=0; //clear send flag 清除发送标志TI1
 264   1        for(i=0;i<data_len;i++)
 265   1           {
 266   2             SBUF = data_buffer[i];           
 267   2             while(TI==0);      //等待串口发送完毕
 268   2             TI=0;     //发送完后,软件清零发送标志TI
 269   2           }
 270   1              
 271   1        ES=1;
 272   1        
 273   1      }
 274          
 275          
 276          /*===========================================
 277          *函数名:串口接收 子函数
 278          *参   数:
 279          *功   能:
 280          *返回值:
 281          *作  者:weishao2401  2009/4/29
 282          *============================================*/
 283          int ydl=0;
 284           void ISRSER() interrupt 4 using 3 //串口中断
 285            {
 286   1        EA=0;  //关中断,防止其它中断打扰
 287   1        if (RI)
 288   1          {
 289   2              rec[count] = SBUF;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -