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

Thu Jun 11 2020, 06:27 AM
anudee
sir could please send the code for I2C and wifi interfacing with 8051
scena
Tue May 19 2020, 10:29 PM
Does anyone have microcontroller programming software for STC15F104W (core 8051, 4 k, 128 byte, 6 I/O pin, UART ... DIL8), that works?
Sat May 02 2020, 07:38 PM
Tamu Gurung
Hi I am looking for a assembly language program for a digital decimal counter. Time counts max limit of 2 mins starting from 2.00 mins and ending at 0.00. time is to be displayed on 4 7-segment LED displays. Edsim51 simulator to be used. Thanks
Wed Mar 25 2020, 01:39 PM
Tajammul
Sir kindly send the code file i2c for 8051
ExperimenterUK
Fri Mar 13 2020, 10:36 PM
@ Rohitnani,ABEBE..which project ?
Fri Mar 13 2020, 12:55 PM
ABEBE
how can get hadwere of this project
Rohitnani
Sat Mar 07 2020, 05:11 PM
Sir, Could you please send me the zip file input password....
Wed Feb 26 2020, 04:58 PM
Peter Parker
Is it possible to send multiple messages using only 1 GSM module?
Sat Feb 01 2020, 10:12 AM
Pearl Olin
Hello,
Wed Jan 22 2020, 06:16 PM
MINU CHAUDHARY
I m getting errors while simulation process during interfacing socket output and lcd... Can i get the report of ur project which is same as us.

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: 77, Members: 0 ...

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

Members: 38215
Newest member: Mirza123