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

rammichael
Tue Jul 25 2017, 10:59 AM
i want few tips to learn to become an expert in embedded systems ...?anybody is there to help me?
Sharmi
Sun Jul 23 2017, 04:13 AM
Sir, I wants to make a digital clock with RTC using AT89C51 or AT89C2051 and seven segment led. Sir will u help me?
Sarvn
Sat Jul 22 2017, 11:42 AM
I wnt to learn embedded could anyone help me
Sarvn
Sat Jul 22 2017, 11:41 AM
Hi
Wed Jul 12 2017, 09:04 AM
Ushiwaka
Any good guides on how to interface an 8255 w/ an 8051?
Tue Jul 11 2017, 12:52 PM
Chiko
i need seconds added to this circuit, can you help me modify it and add codes too
ExperimenterUK
Wed Jul 05 2017, 07:55 PM
@martinsnc115877 The hex file is here http://www.8051projects.net/forum-t65048-post.html
martinsnc115877
Sun Jul 02 2017, 10:58 AM
sir, sorry for the disturbance I can find the small and capital letter,hex file, please send it to me
Sun Jul 02 2017, 06:15 AM
Sam Raj
Can I have the circuit of Simple Digital Voltmeter using 8051
ExperimenterUK
Sat Jul 01 2017, 08:39 PM
Read this http://www.8051projects.net/forum-t65048-post.html. The project download contains lower case letters. It is compiled in Keil

Downloads

Comments

rammichael
Tue Jul 25 2017, 07:12 AM
Rohanmore26
Tue Jul 25 2017, 04:26 AM
AlFaller
Mon Jul 24 2017, 02:31 PM
Sarvn
Sat Jul 22 2017, 11:34 AM
diablom
Fri Jul 21 2017, 01:44 PM
Alihaider.007
Thu Jul 20 2017, 03:07 PM
Vijaykumarsharma
Fri Jul 14 2017, 11:08 AM
varma495
Tue Jul 11 2017, 01:55 AM

Online

Guests: 43, Members: 0 ...

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

Members: 37863
Newest member: rammichael
Forum Activity
Rohanmore26 Avatar
Posted By Rohanmore26
Tue Jul 25 2017, 04:29 AM
Hello I want to know How 3D stitching of 2 3D imag...
AlFaller Avatar
Posted By AlFaller
Mon Jul 24 2017, 02:40 PM
Here is a lot information about using virtual COM ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Jul 20 2017, 04:08 PM
can it be possible ?? Alihaider.007No.You will nee...
Alihaider.007 Avatar
Posted By Alihaider.007
Thu Jul 20 2017, 03:14 PM
Sir I am using AT89S8253 I have trying to use this...
Utsavi Avatar
Posted By Utsavi
Mon Jul 17 2017, 09:57 AM
Hello Ajay_Bhargav,Thanks for your reply. Yes, you...
ajay_bhargav Avatar
Posted By ajay_bhargav
Mon Jul 17 2017, 06:41 AM
I do not think it would be a good idea to kind of ...
ajay_bhargav Avatar
Posted By ajay_bhargav
Mon Jul 17 2017, 06:32 AM
Tasking EDE has linker script facility available y...
Ramweit Avatar
Posted By Ramweit
Thu Jul 13 2017, 06:58 AM
Thank you for response,Sim300 gsm Modem am using h...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jul 11 2017, 04:20 PM
After the SMS is sent the modem should respond+CMG...
Ramweit Avatar
Posted By Ramweit
Tue Jul 11 2017, 02:37 PM
From this code gsm modem sending SMS to mobiles mu...