Discussion in "Embedded GSM Development" started by    Ajay Bhargav    Feb 5, 2013.
Tue Feb 05 2013, 09:10 AM
#1
//You need two variables and a constant, one for storing constant string,
//second for an index pointer and a buffer to store recieved data
unsigned char code Response[] = "+CMTI";
unsigned char MyBuff[15], i = 0;
//we can also have a flag for new message
bit NewMessage = 0;

//consider this ISR function
//assuming ch is read character from SBUF
if((ch == Response[i]) || (i >
 4)){
	//if received character is there in Response or i is >
 4 which means
	// you already have the right string...
	if(ch != 0x0D) { // 0x0D means data received..
		//Store received data
		MyBuff[i++] = ch;
	} else {
		//seems like we have recieved our data
		//Now stop and indicate that new message has received
		MyBuff[i] = '\0';
		NewMessage = 1;
		
		//do not forget to reset i :)
		i = 0; // no more errors..
	}
} else {
	//there is a miss match
	//reset counter
	i = 0;
}

//Now in main loop you can just wait for New message flag

while(!NewMessage);
NewMessage = 0;

//Parse MyBuff, get the index and read message :)


After you go through this pseudo code.. Please read complete discussion in this thread:
http://www.8051projects.net/t41321-p30/embedded-gsm-development/gsm-modem-8051.htm#post_42097
 kirangowle like this.
Tags reading sms from gsm modemreading sms using 8051gsm modem read sms codegsm modem sms reading using interrupt
Tue Feb 05 2013, 10:48 AM
#2
Thanks Ajay Bhargav
Tue Feb 05 2013, 04:46 PM
#3
Thanks to Ajay for this complex logic with simple solution.
Thu Jan 15 2015, 10:43 AM
#4
Hi Ajay ,


I am trying to implement your logic for "Reading SMS from SIM900A GSM Module ". But
Could not succeed .

I have checked my 8051 Circuit and GSM module with Hyperterminal .

I am trying to print the "received string " on LCD and/or send back to hyperterminal

Can you just look in to it ..

Thanks in Advance..

#include<REG51.h>

#include<string.h>


#define dataport P2

sbit rs =	P0^3; 		 //Register select pin
sbit rw =	P0^0;  		 // Fake GND In Hardware
sbit en = 	P0^4;  		 //Enable pin

sbit LED1 =	P1^0;
sbit LED2 =	P1^1;

sbit LED3 =	P0^6;
sbit LED4 =	P0^7;

void rece_isr();

//You need two variables and a constant, one for storing constant string,
//second for an index pointer and a buffer to store recieved data
unsigned char code Response[] = "+CMTI";
unsigned char MyBuff[15], i = 0,ch;
//we can also have a flag for new message
bit NewMessage = 0;

void DelayMs(unsigned char k)
{
   unsigned int i,j;
   for(i=0;i<=k;i++)
   {
   		for(j=0;j<=150;j++) ;
   }
}
void delay(unsigned int msec)  // Function to provide time delay in msec.
{
	int i,j ;
	for(i=0;i<msec;i++)
		for(j=0;j<200;j++);
}
////////////////////////////////////LCD STARTS//////////////////////////////////////
void lcdcmd(unsigned char item)  //Function to send command to LCD
{
	dataport = item;
	rs= 0;
	rw=0;
	en=1;
	delay(1);
	en=0;
	delay(1);
}

void lcddata(unsigned char item)  //Function to send data to LCD
{
	dataport = item;
	rs= 1;
	rw=0;
	en=1;
	delay(1);
	en=0;
	delay(1);
}

int lcd_string(unsigned char *item)    // function to send string to LCD
{
	int x;
	for(x=0;item[x]!=0;x++)
		lcddata(item[x]);
	return(1);
}
void init_lcd()
{
	lcdcmd(0x38);
	delay(1);
	lcdcmd(0x0C);
	delay(1);
	lcdcmd(0x01);
	delay(1);
	lcdcmd(0x80);
	delay(1);
}
////////////////////////////////////LCD ENDS//////////////////////////////////////
////////////////////////////////Serial Program Starts/////////////////////////////
void SerialInit()
{
	EA=0;
	TH1 = 0xFD;
	SCON = 0x50;
	TR1 = 1;
	RI=0;
	TI=0;
	ES=1;
	TMOD = 0x26;
	EA = 1;
}// End of SerialInit
void string_to_pc(unsigned char *temp)
{
	while(*temp)
	{
		SBUF= *temp;
		DelayMs(100);
		temp++ ;
	 }
}


void ISR_sc(void) interrupt 4
{
		//consider this ISR function
		//assuming ch is read character from SBUF
	if((ch == Response[i]) || (i >
4))
		{
							//if received character is there in Response or i is >
 4 which means
				// you already have the right string...
						if(ch != 0x0D) 
						{ // 0x0D means data received..
									//Store received data
									MyBuff[i++] = ch;
									string_to_pc('E');
						} 
						else 
					  {
																	//seems like we have recieved our data
					                       	//Now stop and indicate that new message has received
				              MyBuff[i] = '\0';
				              NewMessage = 1;
											string_to_pc('F');
												//do not forget to reset i :)
										i = 0; // no more errors..
					}
		} else 
				{
							//there is a miss match
							//reset counter
					i = 0;
		    }
}
void rec_unread_sms()
{
	string_to_pc("AT+CMGR=1");
	delay(500);	
	SBUF=0x0D;
	delay(500);	
}

void delete_sms()
{
	delay(1500);	
	string_to_pc("AT+CMGD=1");
	delay(1500);	
	SBUF=0x0D;
	delay(1500);	
}
///////////////////////////////////////////////////

void main()
{

		SerialInit();
	  
	  init_lcd();		                       /* Function for Initlization LCD 16 x 2 */
	
		lcdcmd(0x80);
	
		lcd_string("GSM GATEWAY FOR") ;
	
		lcdcmd(0xC0)                   ;
	
		lcd_string("INDS. MONITORING") ;
	
	  
		lcdcmd(0x01);  
	
		Test_LEDs();
	 	
		while(!NewMessage);
			NewMessage = 0;
	
		lcdcmd(0xC0)                   ;
		lcd_string(MyBuff) ;

	  string_to_pc(MyBuff);
	
		while(1);
}

Sun Jan 18 2015, 05:58 AM
#5
@karan123 I suggest you to create a new thread for your problem.

Get Social

Information

Powered by e107 Forum System

Conversation

Sat May 15 2021, 11:47 AM
Derek Wolcott
Geometric Energy Corporation announced the dogecoin-funded mission on Sunday, with DOGE-1 representing a 40 kilogram cube satellite flying as a payload on a Falcon 9 rocket.
Thu May 13 2021, 07:18 PM
Rufus
Pretty section of content. I just stumbled upon your weblog and in accession capital to assert that I get actually enjoyed account your blog posts. Any way I will be subscribing to your augment and even I achievement you access consistently quickly. https://mkfinstitute.com Trisha Trisha
Wed May 12 2021, 01:23 PM
Jed Roan
Now you can promote your site all over the internet for FREE: http://www3.listofsitesthatacceptfreeads.club
Wed May 12 2021, 08:20 AM
Edgardo
If some one wants to be updated with most recent technologies afterward he must be visit this web page and be up to date every day. annual credit report https://creditscoresetf.com
Wed May 12 2021, 06:11 AM
Laurinda
Great website. A lot of useful information here. I'm sending it to some pals ans also sharing in delicious. And of course, thanks on your effort! annual credit report https://creditscorecheckn.com

Downloads

Comments

Mirza123
Thu Jun 25 2020, 03:46 PM
eunicelove124
Mon Jun 22 2020, 03:03 PM
cerouno
Tue Jun 16 2020, 05:10 PM
Marce
Sat Jun 13 2020, 09:43 PM
Davidthils
Thu May 21 2020, 12:44 PM
Jakeror
Thu May 21 2020, 01:28 AM
motorCar
Wed May 20 2020, 07:05 PM
Vordrync
Wed May 20 2020, 11:52 AM

Online

Guests: 120, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38215
Newest member: Mirza123