我正在尝试将短信发送到动态分配的电话号码。 为此,我使用sim908模块和89v51rd2控制器。 我只是在超级终端上获得AT + CMGS = 976“。之后我无休止地获得垃圾值。 这是我的代码: -
#include <reg51.h>
#include <stdio.h>
sbit BIT1 = P1^0;
sbit BIT2 = P1^1;
char phone_number1[13]= "+919767504200"; // swapnil
char phone_number2[13]= "+919762583395"; // rashmi
char msg1[10] = "HELLO";
char msg2[10] = "SNSYSTEM";
char aux_string[20];
void delay_ms(unsigned int);
void send_sms(char[],char[]);
void serial_init() {
SCON=0x50; //setup for 8-bit data
TMOD=0x20; //setup timer 1 for auto-reload
TH1=0xfd; //Baud Rate 9600
TR1=1; //turn on timer 1
TI=1; //indicate ready to transmit
}
void send_serial(unsigned char *s){
while (*s != 0x0){
SBUF = *s;
while (!TI){
//send_serial("hiii\n");
}
TI = 0;
s++;
}
}
void main(){
BIT1 = 1;
BIT2 = 1;
delay_ms(800);
serial_init(); //Initialize Serial port.
if(BIT1 == 1){
send_sms(phone_number1,msg1);
}
else if(BIT2 == 1){
send_sms(phone_number2, msg2);
}
else{
send_serial("checkpinstatus\n");
}
}
void delay_ms(unsigned int iTime){
unsigned int i,j;
for(i = 0 ; i < iTime ; i++)
for(j = 0 ; j < 1275 ; j++);
}
void send_sms(char phone_number[],char msg[]){
send_serial("AT\r");
delay_ms(400);
send_serial("AT+CMGF=1\r");
delay_ms(400);
sprintf(aux_string,"AT+CMGS=\"%s\"", phone_number);
send_serial(aux_string);
send_serial("\r");
delay_ms(400);
send_serial(msg);
send_serial("\r");
delay_ms(400);
send_serial("0x1A\r");
}