Discussion in "Embedded GSM Development" started by    nizaarr    Apr 2, 2012.
Mon Apr 02 2012, 02:07 pm
#1
dear friends,
i wish to do a project.the description is the message sent should be received by the GSM modem and it should be displayed in the lcd.
Iam using P89V51RD2,SIM300,16X2 LCD.the following is the code which iam using.but it is not working.

what changes shud i make to work it properly...........?





#include<reg51.h>
#include<string.h>
#include<absacc.h>
#include<stdlib.h>

#define buffer 110
sfr port=0xB0;
sbit rs = P2^2;
sbit rw = P2^1;
sbit e = P2^0;
sbit D7 = P3^7;
sbit LED = P2^3;

void delay(unsigned int i);
void lcdcmd(unsigned char val);
void lcddata(unsigned char val);
void lcdinit();
void checkbusy();
void lcdstr(unsigned char *s);
void tx0(unsigned char);
void SMSString(char*text) ;
void init();
void clear(void);
void read_text(unsigned char * , unsigned char * , unsigned char *);
void read_notification();
void clear_mybuff();
void read_msg();

unsigned char abc;
unsigned char idata msg1[buffer];
unsigned char rec_no[10];
unsigned char time_date[20];
unsigned char code Response[] = "+CMTI";
unsigned char MyBuff[20], k = 0;
bit NewMessage = 0;
bit TI_flag = 0;

void lcdstr(unsigned char *s)
{
unsigned int 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 main ()
{
clear();
lcdinit();
lcdcmd(0xd4);
lcddata('K');
delay(10);
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
while(1)
{
IE=0x90;
k=0;
lcdcmd(0xd4);
lcddata('R');
delay(100);
while(!NewMessage);
{
IE=0x00;
lcdcmd(0xd4);
lcddata('I');
delay(10);
NewMessage = 0;
read_notification();
//IE=0x90;
}
}
}
void read_notification()
{

lcdcmd(0x01);
lcdcmd(0xd4);
lcddata('Z');
delay(50);
clear();
SMSString("AT+CMGR=");
tx0(MyBuff[12]);
SMSString("\r");
IE=0x90;
delay(100);
read_msg();
clear();
clear_mybuff();
return;
}
void init()
{
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 serial () interrupt 4 {
unsigned char ch;
if(RI){
ch = SBUF; //character is read
RI = 0; //clear flag
if((ch == Response[k]) || (k > 4))
{
if(ch != 0x0D) // 0x0D means data received..
{
MyBuff[k++] = ch;
}
else
{
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 clear_mybuff()
{
unsigned int a;
for(a=0;a<25;a++)
MyBuff[a]=0x00;
}
void clear(void)
{
unsigned int a;
for(a=0;a<buffer;a++)
msg1[a]=0x00;
}
void read_msg()
{
unsigned char temp[20],i,j;
i=0;
j=0;
do
{
i++;
}while(msg1[i]!='+');
do
{
i++;
}while(msg1[i]!='\n');
do
{
temp[j++]=msg1[i];
}while(msg1[i]!='\r');

lcdcmd(0x80);
lcdstr(temp); // array having message
delay(20);
return;
}
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';

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





pls help me................
Mon Apr 02 2012, 02:46 pm
#2
The above code should work.
See have u made any changes in hardware connection.
Mon Apr 02 2012, 03:56 pm
#3
thnx for replying kiran...

actually i bought the kits seperately.ie,microcontroller board which consist of rs232 and all the things.
and then gsm module.

the only thing which i need to do is connect two DB9 port with a male 2 male connector.so i think there will be no problem with the hardware.....
Mon Apr 02 2012, 07:28 pm
#4
Check attachment.

Mon Apr 02 2012, 08:43 pm
#5
thanx kiran, i vl check it and inform you......
Mon Apr 09 2012, 01:56 pm
#6
@ nizaarr
see the datasheet of P89V51RD2 first
may be there is a need of some configuration of P89V51RD2 to work it like a 89c51
it is better u use at89c52 instead of at89c51 due to ram issue
8051 has 128 bytes of ram
8052 has 256 bytes of ram
Mon Apr 01 2013, 04:58 pm
#7
@kiran
Please tell me that the code you have provided in rar file containing:
GSM_LCD
GSM_LCD1
GSM_LCD2
GSM_LCD3
GSM_LCD4
What is the purpose of these different files and please brief describe that what should i do for converting it in single c file.
Also there is only 1 c file in the folder. Is the entire code written in that only. If yes, then why above said 5 other files are used.????

Thank You
Mon Apr 01 2013, 08:27 pm
#8
Hello Coolest,
You have to take only GSM_LCD.c the other and all are hex file which is generated from that C file. So straight away you can ignore those files.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm
Charlestehed
Wed Apr 24 2024, 05:20 pm
Robertgurse
Wed Apr 24 2024, 02:43 pm
Richardedils
Wed Apr 24 2024, 04:07 am
Malcolmaccek
Wed Apr 24 2024, 01:21 am
ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am