Discussion in "Embedded GSM Development" started by    Ajay Bhargav    Feb 5, 2013.
Tue Feb 05 2013, 02:40 pm
#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, 04:18 pm
#2
Thanks Ajay Bhargav
Tue Feb 05 2013, 10:16 pm
#3
Thanks to Ajay for this complex logic with simple solution.
Thu Jan 15 2015, 04:13 pm
#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, 11:28 am
#5
@karan123 I suggest you to create a new thread for your problem.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Davidbab
Tue Apr 23 2024, 10:41 am
Richardrit
Tue Apr 23 2024, 09:54 am
HenryLaf
Mon Apr 22 2024, 03:50 pm
bleradrar
Mon Apr 22 2024, 06:38 am
ppu-pro_ka
Sun Apr 21 2024, 07:39 pm
Infewow
Sun Apr 21 2024, 06:30 pm
HumanTak
Sun Apr 21 2024, 12:26 pm
Zacharybus
Sun Apr 21 2024, 02:45 am