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

📄 sms.lst

📁 51单片机控制TC35I无线通信模块的完整Keil C程序
💻 LST
📖 第 1 页 / 共 4 页
字号:
C51 COMPILER V7.02a   SMS                                                                  08/28/2005 17:10:47 PAGE 1   


C51 COMPILER V7.02a, COMPILATION OF MODULE SMS
OBJECT MODULE PLACED IN sms.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE sms.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #include "c8051f020.h"                                                          // SFR declarations
   2          //#include "gb2unicode.h"
   3          #include "gb2unicode_char.h"
   4          #include "math.h"
   5          #include "sms.h"
   6          ////////////////////////////////////////////////////////////////////////////
   7          
   8          
   9          UCHAR code ini_display[]={0xc4,0xa3,0xbf,0xe9,0xd2,0xd1,0xd5,0xfd,0xb3,0xa3,0xc6,0xf4,0xb6,0xaf,
  10          0xa3,0xac,0xbf,0xaa,0xca,0xbc,0xb9,0xa4,0xd7,0xf7};
  11          //**************main函数开始************
  12          void main (void)
  13          {  
  14   1          UCHAR i,j;
  15   1          unsigned char xdata sms_rec[200]={0};
  16   1              unsigned char Byte_Len=0;
  17   1              unsigned char String_Len=0;
  18   1              unsigned char xdata Gb_Len=0;
  19   1              unsigned char ch[]="4F60597D000A003C676867AB003E";
  20   1              unsigned char xdata rec_buffer[200]; 
  21   1              unsigned char sms_index_high,sms_index_low;
  22   1              Mcu_ini();
  23   1              led1_close();
  24   1              led2_close();
  25   1              led3_close();
  26   1              Inter_Enable(); 
  27   1              Baudrate_Init();                        //      init the serial port
  28   1              Serial1_Inter_Close();
  29   1              //sound module test
  30   1              Serial1_Inter_Open();
  31   1          Serial0_Inter_Close();
  32   1          //test wireless module
  33   1              sms_receive_flag=0;
  34   1              sms_index_len=0;
  35   1              for(i=0;i<SMS_MAXLENGTH;i++)
  36   1                for(j=0;j<2;j++)
  37   1                sms_index[i][j]='0';
  38   1              sound_ini();
  39   1              start_GSM();
  40   1              //删除卡内所有短信
  41   1              for(i=1;i<10;i++)
  42   1          AT_cmgd('0','0'+i);
  43   1          for(i=0;i<10;i++)
  44   1          AT_cmgd('1','0'+i);
  45   1              //设置收到短信时发送CMTI
  46   1              AT_cnmi();
  47   1              Serial0_Inter_Open();
  48   1          led1_open();
  49   1          send(0xf4);
  50   1          disp_chn(ini_display,12);
  51   1          sound_send(ini_display,24);
  52   1              while(1)
  53   1              {
  54   2              if(sms_index_len>0)
  55   2                {
C51 COMPILER V7.02a   SMS                                                                  08/28/2005 17:10:47 PAGE 2   

  56   3                 led3_open();
  57   3                 Serial0_Inter_Close();
  58   3                 sms_index_high=sms_index[--sms_index_len][0];
  59   3             sms_index_low=sms_index[sms_index_len][1];
  60   3                 Serial0_Inter_Open();
  61   3                 Delay_1S();
  62   3                 Delay_1S();
  63   3             String_Len=AT_cmgr(sms_index_high,sms_index_low,SMS_Buffer);
  64   3                 Byte_Len=String2Bytes(SMS_Buffer, sms_rec,String_Len);
  65   3             Gb_Len=DecodeUcs2(sms_rec, rec_buffer,Byte_Len);
  66   3                 send(0xf4);
  67   3             disp_chn(rec_buffer,Gb_Len);
  68   3             sound_send(rec_buffer,Gb_Len*2);
  69   3                 AT_cmgd(sms_index_high,sms_index_low);
  70   3                 led3_close();
  71   3                }
  72   2          }
  73   1      } 
  74          
  75          /******************************************
  76          //MCU Initialization
  77          Port Configuration and Oscillator set
  78          ==========================================*/
  79          void Mcu_ini(void)
  80          {
  81   1              unsigned char idata delay;
  82   1      
  83   1              OSCXCN = 0x67;                                  // Enable external crystal      
  84   1              WDTCN = 0xDE;                                   // disable watchdog timer
  85   1              WDTCN = 0xAD;
  86   1          XBR0 = 0x04;                        // Set UART0
  87   1         //  XBR0 = 0x00;   
  88   1              XBR1=0x00;                      //disable /INT0,/INT1
  89   1          XBR2 = 0x44;                        // Set UART1,Enable XBAR
  90   1          P0MDOUT = 0x05;                             // Output configuration for P0 P0.0->TX0,P0.2->TX1 Push-Pull, others Open-drain
  91   1      //    P0MDOUT = 0x07;   
  92   1          P1MDOUT = 0x00;                             // Output configuration for P1  all Open-Drain 
  93   1          P2MDOUT = 0x00;                             // Output configuration for P2  all Open-Drain
  94   1          P3MDOUT = 0x3b;                             // Output configuration for P3  P3.2(SOUND_READY),P3.6(LCD_BUSY),P3.7(LCD_REQ) Ope
             -n-Drain,others Push-Pull
  95   1          P0 |= 0x0a;                                 // Enable RX0,RX1
  96   1              P1 |= 0xff;
  97   1          P3 |= 0x44;                                 
  98   1              delay=256;                                              // Delay >1 ms  before polling XTLVLD.
  99   1              while(delay--);
 100   1              while (!(OSCXCN & 0x80));               // Wait until external crystal has                                                                      // started.
 101   1              OSCICN = 0x0C;                                  // Switch to external oscillator
 102   1              OSCICN = 0x88;                                  // Disable internal oscillator; enable 
 103   1                                                      // missing clock detector.
 104   1              while (!(OSCXCN & 0x80));               // Wait until external crystal has                                                                      // started.
 105   1              OSCICN = 0x08;                                  // Switch to external oscillator
 106   1      }
 107          
 108          
 109          /*-------------------------------------------------------------------------
 110          Uart0 and Uart1 Initialization
 111          Uart0 Baudrate:9600bps
 112          Uart1 Baudrate:9600bps
 113          =================================*/
 114          void Baudrate_Init(void)
 115          {
 116   1           //UART0 initialization   use timer2 as baudrate generator
C51 COMPILER V7.02a   SMS                                                                  08/28/2005 17:10:47 PAGE 3   

 117   1           T2CON  = 0x30;             //Set Timer2 as Baudrate Generator of UART0
 118   1           RCAP2H = 0xff;             //Set Reload High Byte
 119   1               RCAP2L = 0xc4;         //Set Reload Low Byte,baudrate=9600bps
 120   1           SCON0  = 0x50;             //Set UART0 Mode 1 (1 Start Bit ,8 Data Bit ,1 Stop Bit) and Enable Receive 
 121   1           
 122   1               //UART1 initialization   use timer4 as baudrate generator
 123   1           T4CON  = 0x30;             //Set Timer4 Mode 2 (Auto Reload Byte)
 124   1           RCAP4H = 0xfe;                     //Set Reload High Byte  
 125   1           RCAP4L = 0x20;                     //Set Reload Low Byte=1200bps 
 126   1           SCON1  = 0x50;             //Set UART1 Mode 1 (1 Start Bit ,8 Data Bit ,1 Stop Bit) and Enable Receive 
 127   1               
 128   1          //**********************  
 129   1          ET2 = 0;                    //Disable Timer2 Interrupt   
 130   1          EIE2 &= 0xfb;               //Disable Timer4 Interrupt 
 131   1          TR2 = 1;                    //Start  Timer2
 132   1              T4CON |= 0x04;         //Start Timer4
 133   1         }  
 134          
 135          //=================================================
 136          //***********Interrupts Open and Close************* 
 137          //=================================================
 138          
 139          void Serial0_Inter_Close()
 140          { ES0=0; }
 141          void Serial0_Inter_Open()
 142          { ES0=1; }
 143          void Serial1_Inter_Close(void)
 144          { EIE2 &= 0xbf; }
 145          void Serial1_Inter_Open(void)
 146          { EIE2 |= 0x4f; }
 147          //========================
 148          //open global interrupts
 149          void Inter_Enable()
 150          {
 151   1      EA=1;
 152   1      }
 153          
 154          void Inter_Disable()
 155          {
 156   1      EA=0;
 157   1      }
 158          //*********************************
 159          
 160          
 161          /*************************************************************************
 162          GSM Program Module
 163          ***************************************************************************/
 164          //*********************************sms函数****************************************
 165          void    start_GSM(void)
 166          {
 167   1              UINT idata i;
 168   1              led2_open();
 169   1      //      for(i=0;i<5;i++) Delay_1S();
 170   1              power_down();
 171   1              start_tc35();
 172   1              for(i=0;i<11;i++) Delay_1S();
 173   1              AT_SEND();
 174   1              Delay_1S();
 175   1              Delay_1S();
 176   1      //      Signal_test();
 177   1      //      Delay_1S();
 178   1              AT_cmgf();
C51 COMPILER V7.02a   SMS                                                                  08/28/2005 17:10:47 PAGE 4   

 179   1              Delay_1S();
 180   1              led2_close();//start complete
 181   1      }
 182          
 183          //cut off power 
 184          void power_down(void)
 185          {
 186   1      PD=1;   //power off
 187   1      Delay_1S();
 188   1      //Delay_1S();
 189   1      //Delay_1S();
 190   1      //Delay_1S();
 191   1      Delay_1S();
 192   1      PD=0;
 193   1      Delay_1S();//wait for module initialization
 194   1      Delay_1S();
 195   1      Delay_1S();
 196   1      Delay_1S();
 197   1      //Delay_1S();
 198   1      //Delay_1S();
 199   1      //Delay_1S();
 200   1      }
 201          
 202          //turn on GSM engine using Ignition line IGT
 203          void start_tc35(void)
 204          {
 205   1      IGT=0;
 206   1      Delay_1S();
 207   1      Delay_1S();
 208   1      IGT=1;
 209   1      }
 210          
 211          void uart0_send(unsigned char data_buffer[],unsigned char data_len)
 212          {
 213   1        unsigned char i;
 214   1        SCON1 &= 0xFD;        //clear send flag
 215   1        for(i=0;i<data_len;i++)
 216   1        {
 217   2          SBUF0 = data_buffer[i];             
 218   2          while(TI0==0); 
 219   2          TI0=0;
 220   2        }
 221   1      }
 222          void AT_SEND(void)              
 223          {
 224   1              UCHAR idata i,error_counter;
 225   1              error_counter=0;
 226   1              while(1)
 227   1              {
 228   2                      TI0=0;
 229   2                      RI0=0;
 230   2                      for(i=0;i<5;i++)
 231   2                      rec[i]=0x00;
 232   2                      start_timer0();
 233   2             uart0_send(Command_At,3);
 234   2                      for(i=0;i<9;i++)
 235   2                      {
 236   3                              while(!RI0);
 237   3                              rec[i]=SBUF0;
 238   3                              RI0=0;
 239   3                      }
 240   2                      close_timer0();
C51 COMPILER V7.02a   SMS                                                                  08/28/2005 17:10:47 PAGE 5   

 241   2      
 242   2                      if(rec[5]=='O'&&rec[6]=='K') break;
 243   2                      else if(error_counter++<10)     Delay_1S();
 244   2                                      else deal_with_error();
 245   2              }
 246   1      }
 247          
 248          
 249          /***********Signal_test函数开始**********
 250          Signal quality test
 251          ****************************/
 252          void    Signal_test(void)
 253          {
 254   1              UCHAR idata     i,error_counter;
 255   1              error_counter=0;
 256   1          while(1)                                           // AT+CSQ
 257   1          {
 258   2                      TI0=0;
 259   2                      RI0=0;
 260   2                      start_timer0();
 261   2              uart0_send(Command_Csq,7);
 262   2              for(i=0;i<28;i++)                                                       //only receive part data (10)
 263   2              {
 264   3                while(!RI0);
 265   3                rec[i] = SBUF0;
 266   3                RI0 = 0;
 267   3                  }
 268   2                  close_timer0();
 269   2             
 270   2              if(rec[15]!= '9'&& rec[16]!= '9') break;  
 271   2              else if(error_counter++<10)     Delay_1S();
 272   2                                      else deal_with_error();
 273   2          }
 274   1              Delay_1S();
 275   1          RI0=0;

⌨️ 快捷键说明

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