Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help!! Does anyone can write concept of programming on sending sms on gprs modem???

Status
Not open for further replies.

Ni yanfang

Member level 3
Member level 3
Joined
Jul 30, 2013
Messages
59
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
432
Help!! Does anyone can write concept of programming on sending sms on gprs modem connect with at89c51??? Kindly give me some ideas>
 

This code is for sending SMS but it doesn't test for modem response. If you want the code which checks the response of modem then I need 1 week time to write the code.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
UART1_Write_Text("AT+CMGF=1");
                 UART1_Write(13);
                 UART1_Write(10) ;
                 Delay_ms(2000);
                 UART1_Write_Text("AT+CMGS=");
                 UART1_Write(0x22);
                 UART1_Write_Text("97xxxxxxxx");
                 Delay_ms(100);
                 UART1_Write(0x22);
                 UART1_Write(13);
                 UART1_Write(10) ;
                 Delay_ms(1000);
                 UART1_Write_Text("Hi! There");
                 UART1_Write(0x0D);
                 UART1_Write(26);
                 UART1_Write(0x0D);

 
i m attaching code...
in this code if switch connected to port 2 is pressed then only sms will send...its working code...
i have used it time ago...so check it and let me know...
Code:
#include<reg51f.h> // include at89x51 . h
#include<stdio.h>// include stdio . h
#include<stdlib.h>// include stdlib . h
#include<string.h>


unsigned char Command_AT[]="AT\r\n";
unsigned char Command_ATI[]="ATI\r\n";
unsigned char Command_ATCOPS[]="AT+COPS?\r\n";
unsigned char Command_ATCREG[]="AT+CREG?\r\n";
unsigned char Command_CMGF[]="AT+CMGF=1\r\n";  // AT+CMGF for selecting Text Mode
unsigned char Command_CMGS[]="AT+CMGS=\"+919619807404\"\r\n"; // recepient mobile number
unsigned char msg02[]="Hello!";

unsigned char okmsg[]="OK";
unsigned char errmsg[]="ERROR";

unsigned char recstr[10]=0,rec_str[10]=0;x=0,n,m; 

void delay(void)
{int d;

for(d=0;d<600;d++);

}

void delay2(void)
{
	unsigned int i;
	for(i=0;i<65535;i++);
}





void initialize_serialcommunication(void)
{                  IE    = 0x90;
				   SCON  = 0x50;
				   TMOD  = 0x20;
		           TH1   = 0xFD;
				   TL1   = 0xFD;
	               TR1   = 1;
				   //RI=0;
		           //TI    = 1;
		          
}



void gsmcmdsend(unsigned char *cmd)
{ 
	
	while(*cmd!='\0')
	{
	 SBUF=*cmd;
	 while(TI==0);
	 TI=0;
 	 cmd++;
	} 
	 
}

void gsmreceive()
{
unsigned char i;
//memset(recstr,'0',sizeof(recstr));
for(i=0;i<2;i++)
{
	if(RI==0);
	{
		delay();
	}
	if (RI==1)
	{
		recstr[i]=SBUF;
		RI=0;
		continue;
	}
		break;
	
}
//return i;
}

void serialrx(void) interrupt 4
{//x=n;
if(RI==0){;}
   recstr[x]=SBUF;
   gsmcmdsend(recstr);
   RI=0;
   
   //n=x;
}
void show_error()
{
 gsmcmdsend(recstr);
 }
void gsminit(void)
{ // AT COMMANDS
unsigned char j,ch=0;

//memset(recstr,0,sizeof(recstr));


	//delay2();
gsmcmdsend(Command_AT);
    
	delay2();
//x=n+1;
	delay2();
	
	//gsmreceive();

ch=strcmp(recstr,okmsg);
	if(ch!=0);
{
	
		show_error();
		return;
	}

	delay2();
    gsmcmdsend(Command_ATI);
	delay2();
    gsmcmdsend(Command_ATCOPS);
	delay2();
    gsmcmdsend(Command_ATCREG);
	delay2();

	gsmcmdsend(Command_CMGF);
	delay2();
	gsmcmdsend(Command_CMGS);
	delay2();
    gsmcmdsend(msg02);
	delay2();
	SBUF = 0x1A;
	while(TI==0); TI = 0;
	 


}


void main (void)
{

unsigned char ch;
P2=0xf0;


initialize_serialcommunication();
	
  while (1)
	{
	while(P2==0xf0);
if(P2==0xb0)gsminit();
	
}

	}
 
i m attaching code...
in this code if switch connected to port 2 is pressed then only sms will send...its working code...
i have used it time ago...so check it and let me know...
Code:
#include<reg51f.h> // include at89x51 . h
#include<stdio.h>// include stdio . h
#include<stdlib.h>// include stdlib . h
#include<string.h>


unsigned char Command_AT[]="AT\r\n";
unsigned char Command_ATI[]="ATI\r\n";
unsigned char Command_ATCOPS[]="AT+COPS?\r\n";
unsigned char Command_ATCREG[]="AT+CREG?\r\n";
unsigned char Command_CMGF[]="AT+CMGF=1\r\n";  // AT+CMGF for selecting Text Mode
unsigned char Command_CMGS[]="AT+CMGS=\"+919619807404\"\r\n"; // recepient mobile number
unsigned char msg02[]="Hello!";

unsigned char okmsg[]="OK";
unsigned char errmsg[]="ERROR";

unsigned char recstr[10]=0,rec_str[10]=0;x=0,n,m; 

void delay(void)
{int d;

for(d=0;d<600;d++);

}

void delay2(void)
{
	unsigned int i;
	for(i=0;i<65535;i++);
}





void initialize_serialcommunication(void)
{                  IE    = 0x90;
				   SCON  = 0x50;
				   TMOD  = 0x20;
		           TH1   = 0xFD;
				   TL1   = 0xFD;
	               TR1   = 1;
				   //RI=0;
		           //TI    = 1;
		          
}



void gsmcmdsend(unsigned char *cmd)
{ 
	
	while(*cmd!='\0')
	{
	 SBUF=*cmd;
	 while(TI==0);
	 TI=0;
 	 cmd++;
	} 
	 
}

void gsmreceive()
{
unsigned char i;
//memset(recstr,'0',sizeof(recstr));
for(i=0;i<2;i++)
{
	if(RI==0);
	{
		delay();
	}
	if (RI==1)
	{
		recstr[i]=SBUF;
		RI=0;
		continue;
	}
		break;
	
}
//return i;
}

void serialrx(void) interrupt 4
{//x=n;
if(RI==0){;}
   recstr[x]=SBUF;
   gsmcmdsend(recstr);
   RI=0;
   
   //n=x;
}
void show_error()
{
 gsmcmdsend(recstr);
 }
void gsminit(void)
{ // AT COMMANDS
unsigned char j,ch=0;

//memset(recstr,0,sizeof(recstr));


	//delay2();
gsmcmdsend(Command_AT);
    
	delay2();
//x=n+1;
	delay2();
	
	//gsmreceive();

ch=strcmp(recstr,okmsg);
	if(ch!=0);
{
	
		show_error();
		return;
	}

	delay2();
    gsmcmdsend(Command_ATI);
	delay2();
    gsmcmdsend(Command_ATCOPS);
	delay2();
    gsmcmdsend(Command_ATCREG);
	delay2();

	gsmcmdsend(Command_CMGF);
	delay2();
	gsmcmdsend(Command_CMGS);
	delay2();
    gsmcmdsend(msg02);
	delay2();
	SBUF = 0x1A;
	while(TI==0); TI = 0;
	 


}


void main (void)
{

unsigned char ch;
P2=0xf0;


initialize_serialcommunication();
	
  while (1)
	{
	while(P2==0xf0);
if(P2==0xb0)gsminit();
	
}

	}

hi. Thank you for your reply. By the way, I am not if my circuit have four switch button connect to at89c51 microcontroller.eg switch 1 connect with p3.3/int1, and rest of switch connect to p1.1 to p1.3. isnt't still working with my circuit? Thanks

- - - Updated - - -

hi. Thank you for your reply. By the way, I am not if my circuit have four switch button connect to at89c51 microcontroller.eg switch 1 connect with p3.3/int1, and rest of switch connect to p1.1 to p1.3. isnt't still working with my circuit? Thanks
Or can I have your mindmap for this programming Please?

- - - Updated - - -

Hi, why this all undefined identifier after I build target, Kindly check for me. Thank you.
Build target 'Target 1'
compiling mywork2.c...
mywork2.c(1): warning C318: can't open file 'reg51f.h'
MYWORK2.C(38): error C202: 'IE': undefined identifier
MYWORK2.C(39): error C202: 'SCON': undefined identifier
MYWORK2.C(40): error C202: 'TMOD': undefined identifier
MYWORK2.C(41): error C202: 'TH1': undefined identifier
MYWORK2.C(42): error C202: 'TL1': undefined identifier
MYWORK2.C(43): error C202: 'TR1': undefined identifier
MYWORK2.C(56): error C202: 'SBUF': undefined identifier
MYWORK2.C(57): error C202: 'TI': undefined identifier
MYWORK2.C(58): error C202: 'TI': undefined identifier
MYWORK2.C(70): error C202: 'RI': undefined identifier
MYWORK2.C(74): error C202: 'RI': undefined identifier
MYWORK2.C(76): error C202: 'SBUF': undefined identifier
MYWORK2.C(77): error C202: 'RI': undefined identifier
MYWORK2.C(88): error C202: 'RI': undefined identifier
MYWORK2.C(89): error C202: 'SBUF': undefined identifier
MYWORK2.C(91): error C202: 'RI': undefined identifier
MYWORK2.C(137): error C202: 'SBUF': undefined identifier
MYWORK2.C(138): error C202: 'TI': undefined identifier
MYWORK2.C(138): error C202: 'TI': undefined identifier
MYWORK2.C(149): error C202: 'P2': undefined identifier
MYWORK2.C(156): error C202: 'P2': undefined identifier
MYWORK2.C(157): error C202: 'P2': undefined identifier
Target not created

- - - Updated - - -

This code is for sending SMS but it doesn't test for modem response. If you want the code which checks the response of modem then I need 1 week time to write the code.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
UART1_Write_Text("AT+CMGF=1");
                 UART1_Write(13);
                 UART1_Write(10) ;
                 Delay_ms(2000);
                 UART1_Write_Text("AT+CMGS=");
                 UART1_Write(0x22);
                 UART1_Write_Text("97xxxxxxxx");
                 Delay_ms(100);
                 UART1_Write(0x22);
                 UART1_Write(13);
                 UART1_Write(10) ;
                 Delay_ms(1000);
                 UART1_Write_Text("Hi! There");
                 UART1_Write(0x0D);
                 UART1_Write(26);
                 UART1_Write(0x0D);


Ok thank. By the way can i have mindmap for your program??Please.
 

Zip and post your keil project files. I will modify it. Mention in detail how the buttons should work.

For hardware, I have gprs modem(q2403) which can insert sim card. I have a rs232 cable and I combine at89c51 circuit with max232.
Then I will connect gprs modem with final circuit (combine at89c51 circuit with max232.)
I will use sample code as mention above, but got error. in this code if switch connected to port 2 is pressed then only sms will send...its working code
I am not if my circuit have four switch button connect to at89c51 microcontroller.eg switch 1 connect with p3.3/int1, and rest of switch connect to p1.1 to p1.3. isnt't still working with my circuit? Thanks
#include<reg51f.h> // include at89x51 . h
#include<stdio.h>// include stdio . h
#include<stdlib.h>// include stdlib . h
#include<string.h>


unsigned char Command_AT[]="AT\r\n";
unsigned char Command_ATI[]="ATI\r\n";
unsigned char Command_ATCOPS[]="AT+COPS?\r\n";
unsigned char Command_ATCREG[]="AT+CREG?\r\n";
unsigned char Command_CMGF[]="AT+CMGF=1\r\n"; // AT+CMGF for selecting Text Mode
unsigned char Command_CMGS[]="AT+CMGS=\"+919619807404\"\r\n"; // recepient mobile number
unsigned char msg02[]="Urgent I need your help!";

unsigned char okmsg[]="OK";
unsigned char errmsg[]="ERROR";

unsigned char recstr[10]=0,rec_str[10]=0;x=0,n,m;

void delay(void)
{int d;

for(d=0;d<600;d++);

}

void delay2(void)
{
unsigned int i;
for(i=0;i<65535;i++);
}





void initialize_serialcommunication(void)
{ IE = 0x90;
SCON = 0x50;
TMOD = 0x20;
TH1 = 0xFD;
TL1 = 0xFD;
TR1 = 1;
//RI=0;
//TI = 1;

}



void gsmcmdsend(unsigned char *cmd)
{

while(*cmd!='\0')
{
SBUF=*cmd;
while(TI==0);
TI=0;
cmd++;
}

}

void gsmreceive()
{
unsigned char i;
//memset(recstr,'0',sizeof(recstr));
for(i=0;i<2;i++)
{
if(RI==0);
{
delay();
}
if (RI==1)
{
recstr=SBUF;
RI=0;
continue;
}
break;

}
//return i;
}

void serialrx(void) interrupt 4
{//x=n;
if(RI==0){;}
recstr[x]=SBUF;
gsmcmdsend(recstr);
RI=0;

//n=x;
}
void show_error()
{
gsmcmdsend(recstr);
}
void gsminit(void)
{ // AT COMMANDS
unsigned char j,ch=0;

//memset(recstr,0,sizeof(recstr));


//delay2();
gsmcmdsend(Command_AT);

delay2();
//x=n+1;
delay2();

//gsmreceive();

ch=strcmp(recstr,okmsg);
if(ch!=0);
{

show_error();
return;
}

delay2();
gsmcmdsend(Command_ATI);
delay2();
gsmcmdsend(Command_ATCOPS);
delay2();
gsmcmdsend(Command_ATCREG);
delay2();

gsmcmdsend(Command_CMGF);
delay2();
gsmcmdsend(Command_CMGS);
delay2();
gsmcmdsend(msg02);
delay2();
SBUF = 0x1A;
while(TI==0); TI = 0;



}


void main (void)
{

unsigned char ch;
P2=0xf0;


initialize_serialcommunication();

while (1)
{
while(P2==0xf0);
if(P2==0xb0)gsminit();

}

}
 

Sorry, I can't help you. You can expect help only if you zip and post the project files. You have posted sanket's code and there is no function definition of gsminit() function. Just post a code which has serial communication code and delay_ms() code.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top