Discussion in "Embedded GSM Development" started by    Alvanbert    Feb 10, 2012.
Fri Feb 10 2012, 08:18 PM
#1
I am currently working on a project to display messages got from the modem to an lcd diaplay. but am still learning how to use the components.

-am using proteus for circuit design
-am using keil for code design

i dont know where to start please help with the code and design.
Sat Feb 11 2012, 07:17 AM
#2
write a simple code to display something on LCD first then we will help you move ahead. Which GSM device are you using now?

[Topic moved to Embedded GSM development Forum]
Sat Feb 11 2012, 10:47 AM
#3
Hi Ajay, I have been reading through the different posts on this forum. and i realised my project is much similar to The on Mr Kirangowle posted a while ago. i am currently figuring out how it works but av realised it still has some problems. i dont want the OK to display onto the LCD display, i want only the sent sms to display. Need some help with this;

Below is the code;
		 #include <REGX52.H>


#define LCD P1
#define LCD_EN		0x80
#define LCD_RS		0x20
                     
//LCD Commands        

#define LCD_SETMODE		   0x04
#define LCD_SETVISIBLE	   0x08
#define LCD_SETFUNCTION	   0x28
#define LCD_SETDDADDR	   0x80

void delayms(unsigned char);
void delayus(unsigned char);
void lcd_init();
void lcd_reset();
void lcd_cmd (char);
void lcd_data(unsigned char);
void lcd_str (unsigned char *);
void clear(void);
void tx0(unsigned char);
void delay_sms (unsigned int);
void SMSString(char*text) ;
void init();
void read_text(unsigned char * , unsigned char * , unsigned char *);

unsigned char j,abc;
unsigned char idata msg1[150];
unsigned char rec_no[20];
unsigned char time_date[20];


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

void main (void)
{
/*
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

use a virtual terminal in Proteus
run a Proteus and right click on virtual terminal and click on option echo character display.
in Proteus there is no mobile model so u should enter text in hyper terminal to suppose gsm Modem is responding.
use serial receive interrupt to receive data
check here

*/
clear();
init();
lcd_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= 901\r"); // AT command to read sms
IE=0X90;   // Enable serial interrupt
delay_sms(2000);

/* i get a response like this

// +CMGR: "REC READ" ,"+2347060580383","10/10/23,14:29:33+04" 
// device1 off 
// Ok. */

// read sms and store in buffer msg1

read_text(msg1,rec_no,time_date);
clear();
IE=0X00;     // Disable all interrupt
while(1);
}


void init(void)
{
j=0;
abc=0;
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
{
while (*text)
{
tx0(*text++);
}
}


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--;
}
}

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
}

void lcd_reset()
{
	LCD = 0xFF;
	delay_sms(40);
	LCD = 0x03+LCD_EN;
	LCD = 0x03;
	delay_sms(40);
	LCD = 0x03+LCD_EN;
	LCD = 0x03;
	delay_sms(5);
	LCD = 0x03+LCD_EN;
	LCD = 0x03;
	delay_sms(5);
	LCD = 0x02+LCD_EN;
	LCD = 0x02;
	delay_sms(5);
}


void lcd_init ()
{
	lcd_reset();
	lcd_cmd(LCD_SETFUNCTION);                    // 4-bit mode - 1 line - 5x7 font. 
	lcd_cmd(LCD_SETVISIBLE+0x04);                // Display no cursor - no blink.
	lcd_cmd(LCD_SETMODE+0x02);                   // Automatic Increment - No Display shift.
	lcd_cmd(LCD_SETDDADDR);                      // Address DDRAM with 0 offset 80h.
 }

 void lcd_cmd (char cmd)
{ 
	LCD = ((cmd >
>
 4) & 0x0F)|LCD_EN;
	LCD = ((cmd >
>
 4) & 0x0F);

	LCD = (cmd & 0x0F)|LCD_EN;
	LCD = (cmd & 0x0F);

    delay_sms(1);
}

void lcd_data (unsigned char dat)
{ 
	LCD = (((dat >
>
 4) & 0x0F)|LCD_EN|LCD_RS);
	LCD = (((dat >
>
 4) & 0x0F)|LCD_RS);
	
	LCD = ((dat & 0x0F)|LCD_EN|LCD_RS);
	LCD = ((dat & 0x0F)|LCD_RS);

    delay_sms(1);
}

void clear(void)
{
unsigned char a;
for(a=0;a<100;a++)
msg1[a]=0x00;
}

void lcd_str (unsigned char *str)
{
	while(*str){
		lcd_data(*str++);
	}
}



I am using a Huawei MODEM
Sun Feb 12 2012, 08:54 AM
#4
@ Alvanbert
start it with pc and hyper terminal
do not come directly to controller
it would be difficult to come directly o controller without testing it with pc
connect he modem with pc using max232 chip
use hyper terminal to see the response of modem
Sun Feb 12 2012, 11:26 AM
#5
Hi majoka, i connected vterm and the modem via COMPIM and attached below are the results as seen from proteus.
The problem is that the receiving terminal replays some commands i enter on the transmitting terminal which i think it shouldnt though this doesnt happen when i use my phone instead, problem is the phone doesnt work with some at commands.

will this affect the final output on the lcd? how can i prevent it?

Mon Feb 13 2012, 02:20 PM
#6


problem is the phone doesnt work with some at commands.

will this affect the final output on the lcd? how can i prevent it?

Alvanbert



Which phone u r using?
U need to use phone which supports AT commands?

Since u r in beginning i prefer u to purchase a GSM SIM300 modem. and try your logic in it.
Tue Feb 14 2012, 03:14 PM
#7
Yes, I got it, now problem is still. How can i extract only message... dont want to want screen to display OK or ERROR... Just want it to display the messages as they come in. e.g if they are 3 messages..it will desplay message 1...then message 2..then message 3...then go back to message 1...the newest message is displayed first in the loop.... messages are deleted after 24 hours..i want to make this automatic in the code...pliz help i know am asking alot but this is what my supervisor asked of me...thanks
Wed Feb 15 2012, 04:11 AM
#8
For that u need to read MSG notification i.e +CMTI:"SM",1 in interrupt routine.
See in same thread u will find Ajay's post.
 ramsesrr like this.
Wed Feb 15 2012, 10:42 AM
#9
@ Alvanbert
which cell phone ur using ?
some cell phones gives error on reading
before reading u need to memory from which u want to read
phone memory or sim memory

firstly u has to go for 1 message
if u do at one 3 will be easy for u

Wed Feb 15 2012, 10:45 AM
#10
Hi Kiran, i looked through Ajay's post and this is what i found;
//as you are using interrupts so its better
//you keep a flag for tx, and instead of polling
// TI, poll that flag

bit TI_flag = 0;

//usage
SBUF = Data_to_send;
while(!TI_flag);
TI_flag = 0;


//Now the ISR.. this what i was expecting...
void serial () interrupt 4 {
        unsigned char ch;
        if(RI){
                ch = SBUF; //character is read
                RI = 0; //clear flag
                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;
                }
        }
        if(TI){
                //if its a tx interrupt
                //clear TI
                TI = 0;
                //set a flag to indicate tx has completed
                TI_flag = 1;
        }
}


The problem is i dont know where to insert it... i have been trying different ways but am always coming up with errors which give me alot of headache. pliz show me where in the code below i should insert the above code. THANX

#include <REGX52.H>


#define LCD P1
#define LCD_EN		0x80
#define LCD_RS		0x20
                     
//LCD Commands        

#define LCD_SETMODE		   0x04
#define LCD_SETVISIBLE	   0x08
#define LCD_SETFUNCTION	   0x28
#define LCD_SETDDADDR	   0x80

void delayms(unsigned char);
void delayus(unsigned char);
void lcd_init();
void lcd_reset();
void lcd_cmd (char);
void lcd_data(unsigned char);
void lcd_str (unsigned char *);
void clear(void);
void tx0(unsigned char);
void delay_sms (unsigned int);
void SMSString(char*text) ;
void init();
void read_text(unsigned char * , unsigned char * , unsigned char *);
read_notification();

unsigned char j,abc;
unsigned char idata msg1[150];
unsigned char rec_no[20];
unsigned char time_date[20];
delay(int);
int NewMessage;

void main ()
{
        clear();
        lcdinit();
        init();
		
SMSString("AT\r"); // AT commands to initialize gsm modem
delay(50);

SMSString( "ATe0\r"); // turn off echo
delay(50);

SMSString( "AT&W\r"); // save settings
delay(50);

SMSString( "AT+CMGF=1\r"); // select text mode for sms
delay(50);
 
SMSString( "AT+CNMI=2,1,0,0,0\r"); // notification of new sms
IE=0x90;
delay(10);

while(!NewMessage);
{
NewMessage = 0;
read_notification();
IE=0x90;
}
//New msg indication.
// +CMTI: "SM",3
}

void read_notification()
{
        IE=0x00;
        clear();
        SMSString("AT+CMGR=");
        tx0(MyBuff[12]);
        SMSString("\r");
        IE=0x90;
        delay(100);
        read_text(msg1,rec_no,time_date);
        clear();

void SMSString(unsigned char* text) //function to send SMS using GSM modem
{
        while (*text)
        {
                tx0(*text++);
        }
}
void tx0(unsigned char x) //send data to serial port 0
{
        EA=0;
        SBUF=x;
        while(!TI_flag);
        TI_flag = 0;
        EA=1;
}
void serial () interrupt 4 {
unsigned char ch;
        if(RI){
      ch = SBUF; //character is read
      RI = 0; //clear flag
      if((ch == Response[k]) || (k >
 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..
                   {
                  MyBuff[k++] = ch;
           }
                   else
                   {
                //seems like we have recieved our data
                //Now stop and indicate that new message has received
                        MyBuff[k] = '\0';
                NewMessage = 1;
                k = 0;
            }
       }
                else
                {
                        msg1[abc]=ch;//received msg is stored.
                        abc++;
                k = 0;
        }
        }
        if(TI)
                {
        //if its a tx interrupt
        //clear TI
                TI = 0;
        //set a flag to indicate tx has completed
            TI_flag = 1;
        }
}

}
 

void init(void)
{
j=0;
abc=0;
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
{
while (*text)
{
tx0(*text++);
}
}


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--;
}
}

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
}

void lcd_reset()
{
	LCD = 0xFF;
	delay_sms(40);
	LCD = 0x03+LCD_EN;
	LCD = 0x03;
	delay_sms(40);
	LCD = 0x03+LCD_EN;
	LCD = 0x03;
	delay_sms(5);
	LCD = 0x03+LCD_EN;
	LCD = 0x03;
	delay_sms(5);
	LCD = 0x02+LCD_EN;
	LCD = 0x02;
	delay_sms(5);
}


void lcd_init ()
{
	lcd_reset();
	lcd_cmd(LCD_SETFUNCTION);                    // 4-bit mode - 1 line - 5x7 font. 
	lcd_cmd(LCD_SETVISIBLE+0x04);                // Display no cursor - no blink.
	lcd_cmd(LCD_SETMODE+0x02);                   // Automatic Increment - No Display shift.
	lcd_cmd(LCD_SETDDADDR);                      // Address DDRAM with 0 offset 80h.
 }

 void lcd_cmd (char cmd)
{ 
	LCD = ((cmd >
>
 4) & 0x0F)|LCD_EN;
	LCD = ((cmd >
>
 4) & 0x0F);

	LCD = (cmd & 0x0F)|LCD_EN;
	LCD = (cmd & 0x0F);

    delay_sms(1);
}

void lcd_data (unsigned char dat)
{ 
	LCD = (((dat >
>
 4) & 0x0F)|LCD_EN|LCD_RS);
	LCD = (((dat >
>
 4) & 0x0F)|LCD_RS);
	
	LCD = ((dat & 0x0F)|LCD_EN|LCD_RS);
	LCD = ((dat & 0x0F)|LCD_RS);

    delay_sms(1);
}

void clear(void)
{
unsigned char a;
for(a=0;a<100;a++)
msg1[a]=0x00;
}

void lcd_str (unsigned char *str)
{
	while(*str){
		lcd_data(*str++);
	}
}


Your help is highly appreciated.

Get Social

Information

Powered by e107 Forum System

Conversation

Sun Apr 30 2017, 05:49 AM
Lijin G Varghese
Can u send me the circuit diagram for Program to interface GSM Module with 8051 microcontroller (AT89C51) using PC and LCD
Sun Apr 30 2017, 05:48 AM
Lijin G Varghese
Program to interface GSM Module with 8051 microcontroller (AT89C51) using PC and LCD
Fri Apr 28 2017, 03:47 PM
SANDEEP T S
I need pcb wizard 3.5 version kindly send valid link of yours
Fri Apr 28 2017, 03:46 PM
SANDEEP T S
I need pcb wizard 3.5 version
ExperimenterUK
Mon Apr 17 2017, 11:56 PM
Sorry..We had a problem with registration.Confirmation emails were not sent.Please re-register
Thu Apr 13 2017, 07:29 PM
Piyush Aughad
I want circuit & program for radar detection using Microcontroller 8051
Tue Apr 11 2017, 03:27 AM
Shabbir Ahmed
Hi Ajay ....hope you and your family all will be fine are you working on andriod aplications if yes then plz reply me
Sun Apr 09 2017, 06:33 PM
ATHULYA NAIR
Dear Sir, I need to know what are the complexity for programming in 8051 Microcontroller for three phase inverter?
Sun Apr 09 2017, 06:32 PM
ATHULYA NAIR
Dear Sir,
Sun Apr 09 2017, 04:43 AM
Rohit chandra joshi
Sir I need ur help urgently.i am trying to make pc controlled led scrolling display using 8051.when i am trying to generate hex file of the code that is given by pratik suthar.it gives the error Target not created Limit:0800h I am using keil uvision4 software. Even i have tried to burn the given hex file that is atteched with the code but my led are not glowing. Pls help me sir .i struck in this problem from last month and till now i am not able to short out the problem. Pls suggest me to solve the problem.mail me at [email protected] Thanks

Downloads

Comments

anshulece
Fri Apr 28 2017, 03:43 PM
Masoooud
Tue Apr 25 2017, 06:57 PM
BOuissal
Mon Apr 24 2017, 02:46 PM
tranhunga
Mon Apr 24 2017, 01:11 AM
Suslik
Sun Apr 23 2017, 09:26 AM
soumk
Sun Apr 23 2017, 06:22 AM
Vavachi1996
Tue Apr 18 2017, 08:01 PM
yasmine
Tue Apr 18 2017, 03:10 PM

Online

Guests: 65, Members: 0 ...

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

Members: 37814
Newest member: anshulece
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon May 01 2017, 12:42 AM
Sorry, that doesn't sound "normal".I think a re-in...
Deepakvaishu Avatar
Posted By Deepakvaishu
Fri Apr 28 2017, 11:18 AM
Yes proteus is loaded ,with all projects.....Once ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Apr 28 2017, 05:06 AM
Does Proteus load at all ?Does it only crash on c...
Deepakvaishu Avatar
Posted By Deepakvaishu
Wed Apr 26 2017, 06:59 AM
hello...I am getting an error when I am trying to ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Apr 18 2017, 10:52 PM
Thanks for the comment.Glad you got it working.
Deepakvaishu Avatar
Posted By Deepakvaishu
Tue Apr 18 2017, 06:19 AM
Thank you very much...Today I got the output for a...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Apr 06 2017, 05:38 PM
Is it initially assigned as '0', and then when the...
Deepakvaishu Avatar
Posted By Deepakvaishu
Thu Apr 06 2017, 07:55 AM
hello,Thanks for the attachment.I have gone throug...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Mar 25 2017, 09:49 PM
I have attached code showing one method you could ...
Deepakvaishu Avatar
Posted By Deepakvaishu
Sat Mar 25 2017, 07:59 AM
I am using Keil and 8051 microcontroller