📄 main.lst
字号:
915 1 }
916
917
918 //发送一条短消息
919 //接收短信的手机,
920 //发送短信的英文内容
921
922 bit sendSMS(byte *telnum, byte *STRING)
923 {
C51 COMPILER V7.10 MAIN 05/03/2007 10:20:04 PAGE 16
924 1
925 1 idata int i,ch,tmp,Len1;
926 1 idata byte Buff[10];
927 1 idata byte A_LEN[4],S_LEN[3];
928 1 byte len, tim ;
929 1
930 1 len = strlen (STRING);
931 1
932 1 len = len <<1; //数据长度 * 2
933 1 Len1 = 0;
934 1 Len1 = len +15;
935 1
936 1 //--- 总消息长度为10进制,的ASCII 码
937 1 sprintf (A_LEN, "%d\n", Len1);
938 1 for(i=0;i<4;i++)
939 1 {
940 2 if(A_LEN[i]==0x0A) A_LEN[i] = 0;
941 2 }
942 1
943 1
944 1 //--- 消息长度为16进制,的ASCII 码
945 1 tim = 0x30+((len & 0xF0 ) >> 4);
946 1 if(tim < 0x30 || tim > 0x39) tim +=0x7;
947 1 S_LEN[0] = tim;
948 1
949 1 tim = 0x30+ (len & 0x0F );
950 1 if(tim < 0x30 || tim > 0x39) tim +=0x7;
951 1 S_LEN[1] = tim;
952 1 S_LEN[2] = 0;
953 1
954 1 tim =10;
955 1 while(tim)
956 1 {
957 2 tim -=1;
958 2 putch('S');
959 2 send_str("AT+CMGS="); // 19\r");
960 2 send_str(A_LEN);
961 2 send_str("\r");
962 2
963 2 if(getAck(4,Buff))
964 2 {
965 3 delay=500000l;
966 3 while(delay--);
967 3 continue;
968 3 }
969 2
970 2 putch(Buff[0]);
971 2 putch(Buff[1]);
972 2 putch(Buff[2]);
973 2 putch(Buff[3]);
974 2
975 2 if ( Buff[2]=='>')
976 2 {
977 3
978 3 send_str("0891683108200005F01100"); //0D9168"); //头
979 3
980 3 send_str(telnum); // 接收短信息的手机
981 3
982 3 send_str("0008A7");
983 3 send_str(S_LEN); //("04"); //(hex) // 信息长度。+ 15 为总长度
984 3
985 3 i = 0;
C51 COMPILER V7.10 MAIN 05/03/2007 10:20:04 PAGE 17
986 3 while(1)
987 3 {
988 4 ch =STRING[i];
989 4 if(ch==0) break;
990 4 PSendChar(0x30);
991 4 PSendChar(0x30);
992 4 tmp = 0x30+((ch & 0xF0 ) >> 4);
993 4 if(tmp < 0x30 || tmp > 0x39) tmp +=0x7;
994 4 PSendChar(tmp);
995 4
996 4 tmp = 0x30+(ch & 0x0F ) ;
997 4 if(tmp < 0x30 || tmp > 0x39) tmp +=0x7;
998 4 PSendChar(tmp);
999 4 i++;
1000 4 }
1001 3 PSendChar(26);
1002 3 BT_REC = 1;
1003 3 delay=5000000L;
1004 3 while(delay--)
1005 3 {
1006 4 if(BT_REC==0)
1007 4 {
1008 5 ch =PGetChar();
1009 5 if(ch=='K') return(0); //发送成功
1010 5 }
1011 4 }
1012 3
1013 3 }
1014 2
1015 2 }
1016 1
1017 1 return(1); // 发送失败
1018 1 }
1019
1020
1021 // 取N个字节.
1022 bit getAck(byte Len,byte *getData)
1023 {
1024 1 byte i;
1025 1 unsigned long m;
1026 1 m = 500000;
1027 1 i = 0;
1028 1 while(m--)
1029 1 {
1030 2 if(BT_REC==0)
1031 2 {
1032 3 getData[i] =PGetChar();
1033 3 BT_REC=1;
1034 3 m = 50000;
1035 3 i+=1;
1036 3 if(i==Len) return(0);
1037 3 }
1038 2
1039 2 }
1040 1 return(1);
1041 1 }
1042
1043 /*
1044 byte sendSMS(byte *telnum, byte *STRING)
1045 {
1046 bit OK =0 ;
1047 idata int i,Len1;
C51 COMPILER V7.10 MAIN 05/03/2007 10:20:04 PAGE 18
1048 idata byte A_LEN[4],S_LEN[3];
1049 byte len, tim,STATUS1;
1050
1051 byte idata TelNum[14];
1052
1053 TelNum[0] =telnum[1];
1054 TelNum[1] =telnum[0];
1055
1056 TelNum[2] =telnum[3];
1057 TelNum[3] =telnum[2];
1058 TelNum[4] =telnum[5];
1059 TelNum[5] =telnum[4];
1060 TelNum[6] =telnum[7];
1061 TelNum[7] =telnum[6];
1062 TelNum[8] =telnum[9];
1063 TelNum[9] =telnum[8];
1064 TelNum[10] ='F';
1065 TelNum[11] =telnum[10];
1066 TelNum[12] =0;
1067
1068 len = strlen (STRING);
1069
1070 len = len /2;
1071 Len1 = 0;
1072 Len1 = len +15;
1073
1074 //--- 总消息长度为10进制,的ASCII 码
1075 sprintf (A_LEN, "%d\n", Len1);
1076 for(i=0;i<4;i++)
1077 {
1078 if(A_LEN[i]==0x0A) A_LEN[i] = 0;
1079 }
1080
1081
1082
1083
1084 //--- 消息长度为16进制,的ASCII 码
1085 tim = 0x30+((len & 0xF0 ) >> 4);
1086 if(tim < 0x30 || tim > 0x39) tim +=0x7;
1087 S_LEN[0] = tim;
1088
1089 tim = 0x30+ (len & 0x0F );
1090 if(tim < 0x30 || tim > 0x39) tim +=0x7;
1091 S_LEN[1] = tim;
1092
1093 S_LEN[2] = 0;
1094
1095
1096 tim =10;
1097 while(tim)
1098 {
1099 tim -=1;
1100 Recv_ok =0;
1101 memset (ComBuffer , '\0', 250);
1102 RecvCnt = 0;
1103
1104 send_str("AT+CMGS="); // 19\r");
1105 send_str(A_LEN);
1106 send_str("\r");
1107
1108 P2_1 = ~ P2_1;
1109 stop_data ();
C51 COMPILER V7.10 MAIN 05/03/2007 10:20:04 PAGE 19
1110
1111 STATUS1=cmp(ComBuffer,">");
1112
1113 if (STATUS1!=0xff)
1114 {
1115 Recv_ok =0;
1116 memset (ComBuffer , '\0', sizeof (RecvCnt));
1117 RecvCnt = 0;
1118
1119 send_str("0891683108200005F011000D9168"); //头
1120
1121 send_str(TelNum); // 接收短信息的手机
1122
1123 send_str("0008A7");
1124 send_str(S_LEN); //("04"); //(hex) // 信息长度。+ 15 为总长度
1125 send_str(STRING);
1126 ES=0;
1127 SBUF=26;
1128 while(TI==0);
1129 TI=0;
1130 ES=1;
1131
1132 delay1 = 10000;
1133 delay2 = 200;
1134
1135 while(delay1)
1136 {
1137 STATUS1=cmp(ComBuffer,"OK");
1138 if (STATUS1!=0xff)
1139 { tim =0;
1140 OK = 1;
1141 break;
1142 }
1143
1144 STATUS1=cmp(ComBuffer,"ERROR");
1145 if (STATUS1!=0xff)
1146 {; break; }
1147
1148 delay2 --;
1149 if (delay2==0)
1150 { delay2 = 100; delay1-=1 ; }
1151
1152 }
1153
1154 }
1155 else
1156 { ; }
1157
1158 }
1159
1160 Recv_ok =0;
1161 memset (ComBuffer , '\0', sizeof (RecvCnt));
1162 RecvCnt = 0;
1163
1164 if(OK) return(0); // 发送成功
1165 else return(0xFF); // 发送失败
1166 }
1167 */
1168
1169
1170 /*
1171 //推荐最小明确数据: 纬度,经度,速度
C51 COMPILER V7.10 MAIN 05/03/2007 10:20:04 PAGE 20
1172 $GPRMC,000000.000,V,0000.0000,S,00000.0000,W,0.00,0.00,220899,,,A*7E
1173 UTC 时间
1174 纬度,
1175 经度
1176 速度
1177 高度
1178 日,月,年
1179 */
1180
1181
1182
1183 // 7-bit编码
1184 // pSrc: 源字符串指针
1185 // pDst: 目标编码串指针
1186 // nSrcLength: 源字符串长度
1187 // 返回: 目标编码串长度
1188 /*
1189 unsigned char gsmEncode7bit(char* pSrc, unsigned char* pDst, unsigned char nSrcLength)
1190 {
1191 unsigned char nSrc; // 源字符串的计数值
1192 unsigned char nDst; // 目标编码串的计数值
1193 unsigned char nChar; // 当前正在处理的组内字符字节的序号,范围是0-7
1194 unsigned char nLeft; // 上一字节残余的数据
1195
1196 // 计数值初始化
1197 nSrc = 0;
1198 nDst = 0;
1199
1200 // 将源串每8个字节分为一组,压缩成7个字节
1201 // 循环该处理过程,直至源串被处理完
1202 // 如果分组不到8字节,也能正确处理
1203 while(nSrc<nSrcLength)
1204 {
1205 // 取源字符串的计数值的最低3位
1206 nChar = nSrc & 7;
1207
1208 // 处理源串的每个字节
1209 if(nChar == 0)
1210 {
1211 // 组内第一个字节,只是保存起来,待处理下一个字节时使用
1212 nLeft = *pSrc;
1213 }
1214 else
1215 {
1216 // 组内其它字节,将其右边部分与残余数据相加,得到一个目标编码字节
1217 *pDst = (*pSrc << (8-nChar)) | nLeft;
1218
1219 // 将该字节剩下的左边部分,作为残余数据保存起来
1220 nLeft = *pSrc >> nChar;
1221 // 修改目标串的指针和计
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -