Discussion in "Embedded GSM Development" started by    aliansari91    Jul 11, 2013.
Thu Jul 11 2013, 12:42 am
#1
#include<reg51.h>

sbit LED=P1^0;
unsigned char r,rx[100],DT[30],m,n,m1[40],msg[10];
void clear(void)
{
unsigned char r;
for(r=0;r<100;r++);
rx[r]=0x00;
}
void clear1(void)
{
unsigned char n;
for(n=0;n<=5;n++);
msg[n]=0x00;
}
void serialcomm()
{
TMOD=0x20;
TH1=0xfd;
SCON=0x50;
TR1=1;
}
void delay(unsigned int value)
{
unsigned int i,j;
for(i=0;i<value;i++);
for(j=0;j<1275;j++);
}
void serial(unsigned char x)
{
SBUF=x;
while(TI==0);
TI=0;
}
void Send2Gsm(char *aaa)
{
unsigned int i;
for(i=0;aaa[i]!=0;i++)
{
serial(aaa[i]);
}
}
void receive_data() interrupt 4
{
rx[r]=SBUF;
RI=0;
r++;
}
void get_msg()
{
do
{
r++;
if(rx[r]=='*');
{
for(n=0;n<=3;n++);
{
msg[n]=rx[r];
r++;
}
}
}while(rx[r]!='?');
}
void main()
{
serialcomm();
Send2Gsm("AT\r\n");
delay(2);
Send2Gsm("AT+CMGF=1\r\n");
delay(2);
out:IE=0x90;
Send2Gsm("AT+CNMI=1,2,0,0,0\r\n");
r=0;
while(1)
{
while(rx[r]=='?')
{
IE=0x00;
get_msg();
if(msg[0]=='*' && msg[1]=='O' && msg[2]=='N')
{
LED=0;
clear();
clear1();
goto out;
}
if(msg[0]=='*' && msg[1]=='O' && msg[2]=='F')
{
LED=1;
clear();
clear1();
goto out;
}
}
}
}
Thu Jul 11 2013, 12:54 am
#2
>unsigned char r,rx[100],DT[30],m,n,m1[40],msg[10];

This line asks the compiler to set aside 183 bytes of ram.
I assume the micro you are using does not have enough memory for that,
plus other memory needed to run your program.

How to solve it ..
Think small, use the smallest buffers you can and share a buffer for tasks that
don't run at the same time.


[ Edited Thu Jul 11 2013, 01:01 am ]
 aliansari91 like this.
Thu Jul 11 2013, 12:20 pm
#3
Thanx for that .. But Error is In main Program...

}while(rx[r]!='?');
}
void main()
{ <<<<<< Error
serialcomm();
Send2Gsm("AT\r\n");
delay(2);
Send2Gsm("AT+CMGF=1\r\n");
delay(2);
out:IE=0x90;
Send2Gsm("AT+CNMI=1,2,0,0,0\r\n");
r=0;
while(1)
{
while(rx[r]=='?')
{
IE=0x00;
get_msg();
if(msg[0]=='*' && msg[1]=='O' && msg[2]=='N')
{
LED=0;
clear();
clear1();
goto out;
}
if(msg[0]=='*' && msg[1]=='O' && msg[2]=='F')
{
LED=1;
clear();
clear1();
goto out;
}
}
}
} <<<< Error
Thu Jul 11 2013, 10:00 pm
#4
@ aliansari91
as there is 128 bytes ram in 8051 and you declaring more than 128 bytes so it can't fit
use 8052 and declare array like

unsigned char idata rx[100];
unsigned char r,DT[30],m,n,m1[40],msg[10];

 aliansari91 like this.
Sat Jul 13 2013, 02:23 pm
#5
ok Thanx..
Sun Jul 14 2013, 10:08 pm
#6
What micro are you using ?
 aliansari91 like this.
Mon Jul 15 2013, 06:45 pm
#7
8051..........
Mon Jul 15 2013, 10:23 pm
#8
This is a common project for the 8051.
Reduce your use of buffers..
m1[] and DT[] don't seem to be used at all.
msg[] could be smaller as you only copy a few bytes to it.
rx[] could be much smaller if you only process small messages. say 20 bytes.

Avoid a buffer overflow by limiting how much you store like this...
void receive_data() interrupt 4
{
if(r >
 19)  //for a 20 byte buffer r must be less than 20
 r=19;

 rx[r]=SBUF;
 RI=0;
 r++;
}


[ Edited Tue Jul 16 2013, 01:14 am ]
 pratikshinde like this.
Mon Jul 15 2013, 10:35 pm
#9
@ aliansari91
these commands can be stored as string in flash by using code keyword (keil C51), which will save run time RAM consumption.
If you want to use more commands, which are constants.

AT\r\n
AT+CMGF=1\r\n
AT+CNMI=1,2,0,0,0\r\n



[ Edited Mon Jul 15 2013, 10:39 pm ]

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am