Discussion in "Embedded GSM Development" started by    kirangowle    Nov 20, 2010.
Sat Nov 20 2010, 06:02 pm
#1
Hi

I am in starting stage of GSM modem(SIM 300). I have wriiten a code where i ll send AT to modem and modem should send OK which i want to display on LCD.

I have interfaced this modem to system its working fine.
 
#include<reg51.h>

#include<string.h>

#include<absacc.h>


sfr port=0xB0;
sbit rs = P2^2;
sbit rw = P2^1;
sbit e = P2^0;
sbit D7 = P0^7;

void delay(unsigned int i);
void lcdcmd(unsigned char val);
void lcddata(unsigned char val);
void lcdinit();
void checkbusy();
char read_frm_gsm();

void lcdcmd(unsigned char val)
{      
        checkbusy();
        P0=val;
        rs=0;
        rw=0;
        e=1;
        delay(1);
        e=0;
        return;
}

void delay(unsigned int i)
{
        unsigned int k, l;
        for(k=0;k<i;k++)
                for(l=0;l<1000;l++);
}
void lcddata(unsigned char val)
{
                checkbusy();
                P0=val;  
                rs=1;
                rw=0;
                e=1;
                delay(1);
                e=0;
        //      return;
}
         

void lcdinit()
{
    lcdcmd(0x38); // 2 lines 5x7 matrix.
    delay(5);
    lcdcmd(0x0c); // Display ON Cursor Blinking.
    delay(5);
    lcdcmd(0x01); // Clear Display Screen.
    delay(5);
    lcdcmd(0x06); // Increment Cursor.
    delay(5);
   
}
void checkbusy()
{
        D7=1;
        rs=0;
        rw=1;
        while(D7!=0)
        {
                e=0;
                delay(1);
                e=1;
        }
}          


void main()
{
	unsigned int i;
	unsigned char temp;
	i=0;	
	lcdinit();
	lcdcmd(0x80);
	lcddata('K');

        TMOD = 0x20;
        SCON = 0x50;
        TH1  = 0xFD;
        TL1  = 0xFD;
        TR1  = 1;
		 
		delay(100);
//	delay(10);
while(1)
{

		i=0;

		SBUF='A';
		while(TI==0);
		TI=0;

		SBUF='T';
		while(TI==0);
		TI=0;
		delay(10);

		while(i<2)
	    {
			i++; 
 		temp=read_frm_gsm();	// Get the datas from the system.
		if(temp == 'O'||temp == 'o')
		{
			lcddata(temp);
			//delay(10);
		}
		temp=read_frm_gsm();	// Get the datas from the system.

		if(temp == 'K'|| temp == 'k')
		{
			lcddata(temp);
			delay(10);
		}
		   i++;
		}


}
}


char read_frm_gsm()
{
	unsigned char chr;
	while(RI==0);
   		chr=SBUF;
		RI=0;
	//	SBUF=chr;
	//	while(TI==0);
	//	TI=0;
return chr;
}

Sat Nov 20 2010, 06:10 pm
#2
modem always send reply (own replies) in CAPS.

almost all command responses starts with "\r\n" or CRLF and also ends with the same.

so if you send AT to modem you will get "\r\nOK\r\n" which are actually 6 bytes. try to modify your code according to that.
Sat Nov 20 2010, 06:18 pm
#3
If that was the problem then LCD should display OK.
I am checking for only 'O' and 'K'
if other character comes it will not enter into the if statment.

	temp=read_frm_gsm();	// Get the datas from the system.

		if(temp == 'O'||temp == 'o')
		{
			lcddata(temp);
			//delay(10);
		}
		temp=read_frm_gsm();	// Get the datas from the system.

		if(temp == 'K'|| temp == 'k')
		{
			lcddata(temp);
			delay(10);
		}


Ajay
For ur ref In my previous code i have directly sent wat ever commands comes from modem to LCD the o/p was some junk values got displayed on LCD.
then i modifed to above code.
Sat Nov 20 2010, 08:51 pm
#4
hi kirangowle
use interrupt method to store data in array that is an effective way when string comes from modem
see this link
http://www.8051projects.net/forum-t39830.html
 kirangowle like this.
Mon Nov 22 2010, 10:19 pm
#5
you have to do dummy read something like this...

read_frm_gsm(); //discard \r
read_frm_gsm(); //discard \n
temp=read_frm_gsm();    // Get the datas from the system.

if(temp == 'O'||temp == 'o')
{
	lcddata(temp);
	//delay(10);
}
temp=read_frm_gsm();    // Get the datas from the system.

if(temp == 'K'|| temp == 'k')
{
	lcddata(temp);
	delay(10);
}
Wed Nov 24 2010, 12:13 pm
#6
Thanks buddies for replying .. sorry late reply..

@ajay
i tried ur solution but didnt get o/p.

@ mojaka.

I referred the link given by u.
From that code i tried to build LCD program to receive msg.
But i m not getting desire output.
Pls help out.
#include <reg51.h>

#include<string.h>

void delay(unsigned int i);
void lcdcmd(unsigned char val);
void lcddata(unsigned char val);
void lcdinit();
void checkbusy();
void lcdstr(unsigned char *s);
//char read_frm_gsm();
void tx0(unsigned char);
void delay_sms (unsigned int);
void SMSString(char*text) ;
void init();

unsigned char j,abc;
unsigned char msg1[100];


void lcdstr(unsigned char *s)
{
 unsigned char l,i;
 l = strlen(s);               // get the length of string
 for(i=1;i<=l;i++)
 {
  lcddata(*s);              // write every char one by one
  s++;  
 }
}
void lcdcmd(unsigned char val)
{      
        checkbusy();
        P0=val;
        rs=0;
        rw=0;
        e=1;
        delay(1);
        e=0;
        return;
}

void delay(unsigned int i)
{
        unsigned int k, l;
        for(k=0;k<i;k++)
                for(l=0;l<1000;l++);
}
void lcddata(unsigned char val)
{
                checkbusy();
                P0=val;  
                rs=1;
                rw=0;
                e=1;
                delay(1);
                e=0;
        //      return;
}
         

void lcdinit()
{
    lcdcmd(0x38); // 2 lines 5x7 matrix.
    delay(5);
    lcdcmd(0x0c); // Display ON Cursor Blinking.
    delay(5);
    lcdcmd(0x01); // Clear Display Screen.
    delay(5);
    lcdcmd(0x06); // Increment Cursor.
    delay(5);
   
}
void checkbusy()
{
        D7=1;
        rs=0;
        rw=1;
        while(D7!=0)
        {
                e=0;
                delay(1);
                e=1;
        }
}          


void serial () interrupt 4
{
msg1[abc]=SBUF;
abc++;
RI=0;
}

void main ()
{

/*
if u do not want to check "OK" response after each AT command then
enable interrupt IE=0X90 ; after last AT command of  
SMSString( "AT+CMGR=1\r"); // AT command to read sms
so after that u recieve a no of bytes from modile if u disable it then u do not reieve
it even data comes
*/
lcdinit();
init();
SMSString("AT\r"); // AT commands to initialize gsm modem
delay_sms(1000);
SMSString( "ATe0\r"); // turn off echo
delay_sms(1000);
SMSString( "AT&W\r"); // save settings
delay_sms(1000);
SMSString( "AT+CMGF=1\r"); // select text mode for sms
delay_sms(1000);
SMSString( "AT+CNMI=2,1,0,0,0\r"); // notification of new sms
delay_sms(1000);
SMSString( "AT+CMGR=1\r"); // AT command to read sms

/* i get a response like this
// +CMGR:"REC READ"," +95445677888", "Date and time", sms text here
// Ok. */

// read sms and store in buffer msg1

delay_sms(1000);
lcdstr(msg1);
delay(10);
while(1);
}


void init()
{
j=0;
abc=0;
IE=0X90;   // Enable serial interrupt
TL1=0XFD; //9600 @ 11.0592
TH1=0xFD;
TMOD=0x20;
SCON=0x50;
TR1=1;
}

void SMSString(unsigned char* text) //function to send SMS using GSM modem
{
unsigned char count = 0;
while (text[count])
{
tx0(text[count++]);
}
}

void tx0(unsigned char x) //send data to serial port 0
{
EA=0;
SBUF=x;
while(TI==0);
TI=0;
EA=1;
}


void delay_sms (unsigned int count)
{
unsigned int i;                         // Keil v7.5a
    while(count) {
        i = 115;
                while(i>
0) i--;
        count--;
}
}



Wed Nov 24 2010, 12:30 pm
#7
hi
see this 5th page of code here is the correct edited code
http://www.8051projects.net/forum-t39830-40.html
array.rar is code but replace function
void read_text( unsigned char *msg,unsigned char *no ,unsigned char *time)
in array.rar with this one
void read_text( unsigned char *msg,unsigned char *no ,unsigned char *time)
{
unsigned char *temp;
temp=msg;
do
msg++;
while(*msg!='+');        
do
msg++;
while(*msg!='+');         //  reaching at no
do
*no++=*msg++;
while(*msg!='"');         // reaching at time
*no++='\0';
msg++;
msg++;
msg++;
do
*time++=*msg++;
while(*msg!='+');         // raching at message
*time='\0';
do
msg++;
while(*msg!='\n');
msg++;
do
*temp++=*msg++;
while(*msg!='\r');       // reaching at end of message
*temp='\0';

lcd_cmd(0x80);            // ist line address
lcd_str(rec_no);          // array having receipt no
lcd_cmd(0xC0);            // 2nd line address
lcd_str(time_date);       // array having date and time
lcd_cmd(0x94);            // 3rd line address
lcd_str(msg1);            // array having message
}


then see the result on lcd
message should be small to filt on lcd let say
hi rickey's world etc
dave do it successfully on hardware
u can see proteus screen shoot there too
what is the error ur facing


[ Edited Wed Nov 24 2010, 12:33 pm ]
Wed Nov 24 2010, 04:04 pm
#8
Hi majoka,

My GSM modem is sim300
What is this "AT+CMGF=1\r", "AT+CNMI=2,1,0,0,0\r"
"AT+CMGR=901\r".
As per my hyper terminal i only require
AT+CMGR= msg no. i.e in box msg no.

Refer the image for more clearity.

Wed Nov 24 2010, 04:24 pm
#9
for
AT+CMGF=1
see this
http://www.developershome.com/sms/operatingMode2.asp

for
AT+CNMI=2,1,0,0,0
see this
http://www.developershome.com/sms/checkCommandSupport3.asp

for
AT+CMGR=901
see this
http://www.developershome.com/sms/cmgrCommand4.asp
from terminal view i see one extra thing that is "kiran"after mobile no that is why decoding is not proper
see this
http://www.8051projects.net/out.php?link=../../e107_files/public/1288613189_24812_FT39830_majoka_replies_3.jpg
it has no word after mobile no so it is not working if u understand the above function
void read_text( unsigned char *msg,unsigned char *no ,unsigned char *time)
then u can easily edit it
if some at commands r extra and u nt need then leave them
Wed Nov 24 2010, 04:44 pm
#10
Hi Majoka,

As per ur link http://www.8051projects.net/out.php?link=../../e107_files/public/1288613189_24812_FT39830_majoka_replies_3.jpg
whether i need that tact switch?

In terminal its showing "kiran" because i have stored my no. into the sim card.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

AntoniaRoons
Fri Apr 19 2024, 09:59 pm
carpinteyrowrl
Fri Apr 19 2024, 02:51 pm
DonaldJAX
Fri Apr 19 2024, 01:08 pm
Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am