speedEC
Full Member level 6
- Joined
- Apr 1, 2011
- Messages
- 337
- Helped
- 23
- Reputation
- 46
- Reaction score
- 21
- Trophy points
- 1,298
- Activity points
- 4,324
AT+CMGS="9xxxxxxxxxxx" //
check for '>' character
Message
cntrl Z
here i'm sending these commands as a string.
How shud i send the number..in double inverted comma "9xxxxxxxxx"
send_string("AT+CMGS="9xxxxxxxxx"");
enter();
send_string("AT+CMGS=\"9xxxxxxxxx\"");
OR
send_string("AT+CMGS=");
send_char(0x22);
send_string("9xxxxxxxxx");
send_char(0x22);
<Enter>
wait for >
message
<ctrl><Z>
and how to send a message to multiple numbers ??
can we use AT+CMGW command to store the message at particular memory location and later sending it to multiple numbers ??
...By using that and AT+CMSS command i can send the same message to multiple recipients.
but i hv one doubt by sending sms using CMSS command it will store the sent message copy in the memory. Then after some msgs memory will be full. It will be difficult to delete message copy as we hv to search everytime the memory location for sent message copy and delete them. SO what shud i do ??....
...It sends +CMTI: index no whnevr new sms comes. AM i going correctly ?...
or is there any other way like serial interrupt( whenevr +cmti comes it shud go to particular ISR) ?..
void interrupt isr(){
if (RCIE && RCIF){
char GSM_REPLY = getch(); // Hi-tech c for PIC16
RCIF = 0;
}
}
while(1){
char GSM_REPLY = getch(); // Hi-tech c for PIC16
}
what is RCIE and RCIF...would you plz elaborate1. You can set and enable RCIE and store the GSM data to (by combining data) string whenever RCIF interrupt occurred.
For example,
Code:
void interrupt isr(){
if (RCIE && RCIF){
char GSM_REPLY = getch(); // Hi-tech c for PIC16
RCIF = 0;
}
}
ORG 0H
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON,#50H
SETB TR1
ACALL INT_LCD
H_1: MOV DPTR,#MSG_1
CLR A
MOVC A,@A+DPTR
JZ B_1
ACALL SEND
INC DPTR
SJMP H_1
B_1: ACALL DELAY
ACALL RECV
ACALL DATAWRT
ACALL CLR_LCD
ACALL INT_LCD
H_2: MOV DPTR,#MSG_2
CLR A
MOVC A,@A+DPTR
JZ B_2
ACALL SEND
INC DPTR
SJMP H_2
B_2: ACALL DELAY
ACALL RECV
ACALL DATAWRT
ACALL CLR_LCD
INT_LCD:
MOV A,#38H
ACALL COMNWRT
ACALL DELAY
MOV A,#0EH
ACALL COMNWRT
ACALL DELAY
MOV A,#06H
ACALL COMNWRT
ACALL DELAY
RET
COMNWRT:
MOV P1,A
CLR P0.0
SETB P0.1
ACALL DELAY
CLR P0.1
RET
DELAY:
MOV R0,#10
HERE3: MOV R3,#250
HERE2: MOV R4,#255
HERE1: DJNZ R4,HERE1
DJNZ R3,HERE2
DJNZ R0,HERE3
RET
SEND: MOV SBUF,A
H: JNB TI,H
CLR TI
RET
RECV: JNB RI,RECV
MOV A,SBUF
CLR RI
RET
MSG_1: DB "AT",0
MSG_2: DB"AT+CMGF=1",0
DATAWRT:
MOV P1,A
SETB P0.0
SETB P0.1
ACALL DELAY
CLR P0.1
RET
CLR_LCD:
MOV A,#01H
ACALL COMNWRT
ACALL DELAY
RET
END
helloConnection = MCU board to MAX232 to DB9 Connector to SIM300 board DB9 Connector.
#include<reg51.h>
#include<intrins.h>
#include<string.h>
sbit relay=P2^7;
void data_send(unsigned char *);
void delay1();
void compare();
void data_send1(unsigned char *);
void command_mode(unsigned char );
void busy();
void data_res();
void lcd_init();
void gsm_receive();
void gsm_send(unsigned char *);
void delay();
void data_mode(unsigned char *);
void data1_mode(unsigned char);
unsigned char data_receive();
void intialisation();
sbit rs=P0^0;
sbit rw=P0^4;
sbit en=P0^1;
sbit en1=P1^7;
unsigned char *ch="AT\r\n";
unsigned char *ch1="AT+CMGF=1\r\n";
unsigned char *ch2="AT+CMGS=";
unsigned char *ch3="Hi world\r\n";
unsigned char *ch4="AT+CNMI=2,2,0,0,0\r\n";
unsigned char *ch5="AT+CMGR=1\r\n";
unsigned char *ch6="AT+CMGD=1\r\n";
unsigned char *ph1="+919717856679";
unsigned char *msg1="MOTOR ON";
unsigned char *msg2="MOTOR OFF";
unsigned char *ch7="ATEO\r\n";
unsigned char *ch8="AT&W\r\n";
unsigned char *ch9="+919717856688";
unsigned char a[2],cha,ph[14],msg[10],count=0,count1=0;
int main()
{
unsigned char j=0,cha;
P1=0x00;
P2=0x00;
rs=0;
rw=0;
en=0;
en1=1;
SCON=0x50;
TMOD=0x20;
TH1=0xfd;
TR1=1;
a[0]='"';
a[1]='\0';
//gsm_send();
lcd_init();
gsm_receive();
while(1)
{
command_mode(0x80);
cha=data_receive();
//command_mode(0x01);
while(cha!='+')
{
cha=data_receive();
}
//command_mode(0x01);
while(cha!='+')
{
cha=data_receive();
}
while(cha!='9')
{
cha=data_receive();
}
while(cha!='1')
{
cha=data_receive();
}
command_mode(0x01);
for(j=0;j<10;j++)
{
cha=data_receive();
ph[j]=cha;
}
ph[j]='\0';
while(cha!='\n')
{
cha=data_receive();
}
j=0;
cha=data_receive();
while(cha!='\n')
{
msg[j]=cha;
cha=data_receive();
j++;
}
msg[j-1]='\0';
compare();
}
return 0;
}
void data_send(unsigned char *p)
{
while(*p!='\0')
{
SBUF=*p;
while(TI==0);
TI=0;
p++;
}
}
unsigned char data_receive()
{
unsigned char i=0,j=0,ch;
RI=0;
while(RI==0);
ch=SBUF;
return ch;
}
void data_res()
{
unsigned char i=0;
while(i<4)
{
unsigned char ch;
RI=0;
while(RI==0);
ch=SBUF;
i++;
}
}
void compare()
{
unsigned char j=0;
if(strcmp(ph,ph1)==0&&strcmp(msg,msg1)==0)
{
data_mode("Valid msg & no");
command_mode(0xc0);
data_mode(msg);
relay=1;
count1=0;
ch9=ph;
if(count>0)
{
gsm_send("MOTOR ALREADY ON");
}
else
{
gsm_send("MOTOR ON");
}
count++;
}
else if(strcmp(ph,ph1)==0&&strcmp(msg,msg2)==0)
{
data_mode("Valid msg & no");
command_mode(0xc0);
data_mode(msg);
relay=0;
count=0;
ch9=ph;
if(count1>0)
{
gsm_send("MOTOR ALREADY OFF");
count=0;
}
else
{
gsm_send("MOTOR OFF");
}
count1++;
}
else if(strcmp(ph,ph1)!=0&&strcmp(msg,msg1)!=0)
{
ch9=ph;
data_mode("Invalid no & msg");
gsm_send("you r not authorised");
}
else if(strcmp(ph,ph1)!=0||strcmp(msg,msg1)!=0)
{
if(strcmp(ph,ph1)!=0)
{
ch9=ph;
data_mode("Invalid no");
command_mode(0xc0);
data_mode(ph);
gsm_send("you r not authorised");
}
else{
ch9=ph;
data_mode("Invalid msg");
command_mode(0xc0);
data_mode(msg);
gsm_send("Invalid msg");
}
}
}
void command_mode(unsigned char a)
{
busy();
rs=0;
rw=0;
P1=a;
en=1;
_nop_();
_nop_();
en=0;
}
void busy( )
{
en1=1;
rs=0;
rw=1;
while(en1)
{
en=0;
_nop_();
_nop_();
en=1;
}
}
void data_mode(unsigned char *p)
{
busy();
rs=1;
rw=0;
while(*p!='\0')
{
P1=*p;
intialisation();
p++;
}
}
/*void data1_mode(unsigned char p)
{
busy();
rs=1;
rw=0;
P1=p;
intialisation();
}*/
void intialisation()
{
en=1;
_nop_();
_nop_();
en=0;
}
void gsm_send(unsigned char *ch3)
{
data_send(ch);
data_res();
data_send(ch1);
data_res();
data_send(ch2);
data_res();
data_send(a);
data_send(ch9);
data_send(a);
data_send("\r\n");
data_send(ch3);
data_res();
SBUF=0x1a;
while(TI==0);
TI=0;
}
void gsm_receive()
{
data_send(ch7);
data_res();
data_send(ch8);
data_res();
data_send(ch1);
//delay();
data_res();
data_send(ch4);
//delay();
data_res();
}
void lcd_init()
{
command_mode(0x01);
command_mode(0x38);
command_mode(0x06);
command_mode(0x80);
command_mode(0x0f);
}
/*void delay1()
{
TMOD=0x01;
TH0=0x00;
TL0=0x00;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}*/
/*void delay()//10ms delay
{
TMOD=0x01;
TH0=0xdb;
TL0=0xff;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}*/
i have checked that my lcd is working fine with the 8052 but i am not able to communicate with sim900
my modem is giving response with mcu
but its not showing any connection with pc
and i have lcd connected to my mcu and that's working perfect
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?