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

📄 debug.lst

📁 51单片机收发短信的程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
1050   2                      tmp=original;
1051   2                      tmp=tmp<<index;
1052   2          if(tt==0)
1053   2          {
1054   3            dest[j]=(tmp&0x7f)+remainder;
1055   3            j++;
1056   3            dest[j]=(original>>1)&0x7f;
1057   3            remainder=0;
1058   3          }
1059   2          else
1060   2          {
1061   3            dest[j]=(tmp&0x7f)+remainder;
1062   3            remainder=original>>(8-index-1);
1063   3          }
1064   2      
1065   2          j=j+1;
1066   2              }
1067   1              dest[sms_deliver.PDUDataLen]=0;
1068   1      }
1069          //////////////function:发送AT+CMGS命令,然后发送数据信息///////////////////////
1070          void send_response()
1071          {
1072   1        uchar    tmp=0;
1073   1        uchar    lenoflen,quot;
1074   1        uchar    bitcodedlen       = 0;
1075   1        tmp=strlen(sms_deliver.PDUData);
1076   1        quot=tmp/8;
1077   1        bitcodedlen=quot*7+tmp%8;                 //the length of the PDUData after compact(7->8)
1078   1         ///发送前先检验网络注册情况
1079   1            send_string("AT+COPS=0\r");  //GSM network operator is to be selected automatically
1080   1            delay_1s();
1081   1            delay_1s();
1082   1            put_string(0x80,RcvBuf); //显示出来返回的结果
1083   1            send_string("AT+COPS?\r");  //read the status to GSM network operator
1084   1            delay_160ms();
1085   1            put_string(0x80,RcvBuf); //显示出来返回的结果
1086   1        strcpy(CMDBuf,"AT+CMGS=");                //AT+CMGS=<数据长度>命令
1087   1        lenoflen=itoa(bitcodedlen+PhoneNumLen+2,CMDBuf+8); //PhoneNumLen+2位手机号码 8:"AT+CMGS="八个字符
1088   1        CMDBuf[8+lenoflen]=CR;
1089   1        CMDBuf[8+lenoflen+1]=0;
1090   1        send_string(CMDBuf);                      //send command
1091   1        delay();
1092   1        encode_message();
1093   1        delay_160ms();
1094   1        send_string(SendBuf);                     //send SMS
1095   1        delay_1s();
1096   1        delay();
1097   1      }
1098          ////////////////////function:convert the PDU data to SMS////////////////////////
1099          void PDU2SMS(char  * Buf)
1100          {
1101   1        uchar   index=0;
1102   1        delay();
1103   1        sms_deliver.SMSCLen=hex2int(Buf);
1104   1        sms_deliver.AddressType[0]=Buf[2];
1105   1        sms_deliver.AddressType[1]=Buf[3];
1106   1        sms_deliver.AddressType[2]=0;
1107   1        PDUHalf8bitDecode(Buf+4,(sms_deliver.SMSCLen-1)*2,sms_deliver.ServiceCenter);
1108   1        sms_deliver.ServiceCenter[16]=0;
1109   1        index=4+(sms_deliver.SMSCLen-1)*2;
C51 COMPILER V7.02a   DEBUG                                                                04/01/2005 10:28:51 PAGE 19  

1110   1        sms_deliver.SMSDeliver1[0]=Buf[index];
1111   1        sms_deliver.SMSDeliver1[1]=Buf[index+1];
1112   1        sms_deliver.SMSDeliver1[2]=0;
1113   1        index=index+2;
1114   1        sms_deliver.PhoneNumLen=hex2int(Buf+index);
1115   1        sms_deliver.PhoneNumType[0]=Buf[index+2];
1116   1        sms_deliver.PhoneNumType[1]=Buf[index+3];
1117   1        sms_deliver.PhoneNumType[2]=0;
1118   1        memset(sms_deliver.PhoneNumber,'\0',strlen(sms_deliver.PhoneNumber));
1119   1        PDUHalf8bitDecode(Buf+index+4,sms_deliver.PhoneNumLen,sms_deliver.PhoneNumber);
1120   1        sms_deliver.PhoneNumber[sms_deliver.PhoneNumLen]=0;
1121   1        index=index+4+sms_deliver.PhoneNumLen+1;
1122   1        sms_deliver.ProtocolFlag[0]=Buf[index];
1123   1        sms_deliver.ProtocolFlag[1]=Buf[index+1];
1124   1        sms_deliver.ProtocolFlag[2]=0;
1125   1        sms_deliver.EncodeType[0]=Buf[index+2];
1126   1        sms_deliver.EncodeType[1]=Buf[index+3];
1127   1        sms_deliver.EncodeType[2]=0;
1128   1        PDUHalf8bitDecode(Buf+index+4,14,sms_deliver.TimePost);
1129   1        sms_deliver.TimePost[14]=0;
1130   1        sms_deliver.PDUDataLen=hex2int(Buf+index+18);
1131   1        if(strcmp(sms_deliver.EncodeType,"00")==0)
1132   1          PDU7BitDecode(Buf+index+20,sms_deliver.PDUData);
1133   1        if(sms_deliver.PhoneNumLen)
1134   1          PhoneNumLen=sms_deliver.PhoneNumLen;
1135   1        delay();
1136   1      }
1137          ///////////////////function: decode phone///////////////////////////////////////
1138          void PDUHalf8bitDecode(char  * str,uchar  len,char  * dest)
1139          {
1140   1              char   i=0;
1141   1        for(i=0;i<len;i=i+2)
1142   1              {
1143   2                dest[i]=str[i+1];
1144   2                dest[i+1]=str[i];
1145   2              }
1146   1              if(dest[len-1]=='F')
1147   1                dest[len-1]=0;
1148   1      
1149   1      }
1150          ///function:process the new SMS,check if the center phone is changed////////////
1151          void Data_processing()
1152          {
1153   1        delay();
1154   1        if(sms_deliver.EncodeType[1]=='0')
1155   1        {
1156   2          if(strncmp(sms_deliver.PDUData,"ABC123",6)==0)
1157   2          //正确的数据格式:密码(ABC123)+手记号码(8613810736479)+校验和
1158   2          {
1159   3            if(ascii_verify(sms_deliver.PDUData))
1160   3            {
1161   4              memset(center_phone,0,sizeof(center_phone));
1162   4              strncpy(center_phone,sms_deliver.PDUData+6,sms_deliver.PDUDataLen-8);
1163   4        //    sequential_write(0x8000,PhoneNumLen+1,center_phone);    //保存上位机号码
1164   4                                                                      //(同时要保存PhoneNumLen?)
1165   4            }
1166   3            memset(sms_deliver.PDUData,0,sizeof(sms_deliver.PDUData));
1167   3          }
1168   2        }
1169   1      }
1170          ///////////////////////function:string verify///////////////////////////////////
1171          char ascii_verify(uchar  * dest)
C51 COMPILER V7.02a   DEBUG                                                                04/01/2005 10:28:51 PAGE 20  

1172          {
1173   1        char    i      = 0;
1174   1        uchar   result = 0;
1175   1        uchar   tmp[3];
1176   1        uchar   count  = strlen(dest)-2;
1177   1        for(;i<count;i++)
1178   1        {
1179   2          result+=dest[i];
1180   2        }
1181   1        tmp[0] = dest[count];
1182   1        tmp[1] = dest[count+1];
1183   1        tmp[2] = 0;
1184   1        if(result==hex2int(tmp))
1185   1          return 1;
1186   1        else
1187   1          return 0;     //////应该是return 0
1188   1      }
1189          //////////////function:编码形成短信,送到SendBuf中//////////////////////////////
1190          void encode_message()
1191          {
1192   1        char   phone[15];
1193   1        memset(SendBuf, '\0', sizeof (SendBuf));
1194   1        memset(phone, '\0', sizeof (phone));
1195   1        encode_phone(phone);  //将center_phone编码为phone
1196   1        strcpy(SendBuf,"0891683108100005F0");
1197   1        strcpy(SendBuf+strlen(SendBuf),"11000D91");
1198   1        strcpy(SendBuf+strlen(SendBuf),phone);
1199   1        strcpy(SendBuf+strlen(SendBuf),"0000A7");
1200   1        int2hex(strlen(sms_deliver.PDUData),SendBuf+strlen(SendBuf));
1201   1        PDU7BitEncode(sms_deliver.PDUData,SendBuf+strlen(SendBuf));
1202   1        SendBuf[strlen(SendBuf)+1]=0;
1203   1        SendBuf[strlen(SendBuf)]=0x1A;
1204   1      }
1205          ///////////////function:对手机号码编码//////////////////////////////////////////
1206          unsigned char encode_phone(char  *dest)
1207          {
1208   1        uchar  i,j;
1209   1        j=0;
1210   1        for(i=0;i<PhoneNumLen+1;i++)
1211   1        {
1212   2          if(j==0)
1213   2          {
1214   3            dest[i]=center_phone[i+1];
1215   3            j=1;
1216   3          }
1217   2          else
1218   2          {
1219   3            dest[i]=center_phone[i-1];
1220   3            j=0;
1221   3          }
1222   2        }
1223   1        if(PhoneNumLen%2!=0)          ///如果上位机号码位数是奇数个
1224   1          dest[PhoneNumLen-1]='F';
1225   1        dest[PhoneNumLen+1]=0;
1226   1        return PhoneNumLen+1;
1227   1      }
1228          /////////function://功能类似于int2hex,增加到三位,并且各位都在0~9之间////////
1229          char itoa(char  num , char  *str)
1230          {
1231   1          uchar     hundred=num/100;
1232   1          uchar     ten=(num-hundred*100)/10;
1233   1          uchar     base=(num-hundred*100-ten*10);
C51 COMPILER V7.02a   DEBUG                                                                04/01/2005 10:28:51 PAGE 21  

1234   1          uchar     index=0;
1235   1      
1236   1              if(hundred!=0)
1237   1              {
1238   2              str[index]=hundred+NUMBASE;
1239   2                      index=index+1;
1240   2              }
1241   1              if(ten!=0)
1242   1                  {
1243   2                      str[index]=ten+NUMBASE;
1244   2                      index=index+1;
1245   2                  }
1246   1      
1247   1          str[index]=base+NUMBASE;
1248   1          str[index+1]=0;
1249   1          return index+1;
1250   1      }
1251          /////////////////////////function:delay 5s//////////////////////////////////////
1252          void wait_5s()
1253          {
1254   1          uint idata i;
1255   1          char idata  j;
1256   1          for(i=0;i<5000;i++)
1257   1          {
1258   2               delay();
1259   2               for(j=0;j<14;j++)
1260   2                  _nop_();
1261   2                 delay();
1262   2                if(bResponsed)  //如果收到短信,跳出延时程序
1263   2                  break;
1264   2          }
1265   1          bResponsed=0;
1266   1      }
1267          ///////////////////////////////////////////////////////////////////////////////////////
1268          ///////////////////SFR和各全局变量、开机界面等的初发始化///////////////////////////////
1269          ///////////////////////////////////////////////////////////////////////////////////////
1270          void startup_init()
1271          {
1272   1        char i;
1273   1        PMR = PMR | 0x01;  //W77E58允许使用片内的1K SRAM
1274   1      //  AUXR=0x01;        //EXTRAM=0:访问物理上在内部,逻辑上在外部的RAM;
1275   1                          //ALEOFF=1:禁止ALE输出,以降低对外界的EMI干扰
1276   1      //  WDT_CONTR=0x30;      //看门狗定时71.1ms,具体设置见PDF文档(喂狗语句应为WDT_CONTR=0x30;)
1277   1        TH1=0xfd;
1278   1        TL1=0xfd;  //串口波特率设置9600
1279   1        TMOD=0x20;          //GATE1=0; GATE0=0,C/T=0,M1=1,M0=0, 定时器工作模式选择
1280   1        IP=0x10;  // PS=0, 串口中断为高优先级中断
1281   1        SCON=0x50;       // 串口工作方式选择,异步8位,mode=10 ren1
1282   1        PCON=0x00;       // 波特率不倍增
1283   1        TR1=1;  //启动定时器
1284   1        IE=0x90;             //EA=1;ES=1;ET1=0;EX1=1;ET0=0;EX0=0;
1285   1        P1=0x0f;             //键盘八条线四高四低
1286   1      
1287   1        display_type=0;       //0:品种界面1:价格界面2:已存信息内容
1288   1        vege_page_index=0;              //蔬菜品种页面索引为 0
1289   1        info_page_index=0;      //已存蔬菜信息页面索引置初值0
1290   1        info_count=0;      //已存信息条数置初值0
1291   1        vege_type[0]='\0';      //蔬菜品种置初值'\0'
1292   1        vege_type[1]='\0';      //同上
1293   1        vege_type[2]='\0';
1294   1        for(i=0;i<=4;i++)
1295   1          vege_price[i]='\0';   //蔬菜价格置初值' '
C51 COMPILER V7.02a   DEBUG                                                                04/01/2005 10:28:51 PAGE 22  

1296   1        memset(ListBuf,0,sizeof(ListBuf));
1297   1        memset(PDUBuf,0,sizeof(PDUBuf));
1298   1        memset(RcvBuf, '\0', sizeof (RcvBuf));
1299   1        memset(SendBuf, '\0', sizeof (SendBuf));
1300   1        memset(&sms_deliver ,0,sizeof(sms_deliver));
1301   1        memset(CMDBuf,0,sizeof(CMDBuf));
1302   1        memset(sms_deliver.PDUData,0,sizeof(sms_deliver.PDUData));
1303   1        strcpy(center_phone,"8613752061177");
1304   1        init_LCD();           //初始化LCD;
1305   1        put_string(0x90,"  ");        //显示定位,如果没有这条语句,显示经常不对
1306   1        put_string(0x90,"初始化...");  //开机显示的字符串
1307   1      }
1308          ////////////////////////////////////////////////////////////////////////////////////////
1309          /////////////main()函数,做所有需要初始化的工作都在main()///////////////////////////////
1310          ////////////////////////////////////////////////////////////////////////////////////////
1311          //全部的初始化工作
1312  

⌨️ 快捷键说明

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