Problem receiving a message through sim 900

Status
Not open for further replies.

alifaizan1992

Newbie level 1
Joined
Jan 1, 2013
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,316
Hello Everyone , I m doing my semester project on sim 900 with 89c52 . I m able to send a message to my mob no. but cannot receive any thing thorugh "AT+CNMI=1,1,0,0,0" and "AT +CMGR=index" need urgent help . I m attaching code along



#include<reg51.h>
#include<string.h>
unsigned char sms='0';
unsigned char count='a';
unsigned char index='0';

void cct_init(void);
void delay(int);
void lcd_set(void);
void display_function_lcd(unsigned char *str);
void write_instruct(int);
void writedata(char);
void lcd_busy(void);
char READ_SWITCHES(void);
char get_key(void);
void make_array_buffer(char a);
void send_sms(unsigned char *str);
void read_message(void);
char rx0(void);
void delete_msg(void);
void handle_index(void);
void handle_msg(void);
void del_msg(void);
//void check_response(void);
void receive_interrupt(void) interrupt 4
{
display_function_lcd("ISR CALLED");
write_instruct(0x01);
write_instruct(0x80);
writedata(count);
if(count=='a')
{
handle_index();
RI=0;

return;

}

if (count !='a')
{
handle_msg();
RI=0;
del_msg();
return;
}

}

/*
sbit RowA = P1^0;
sbit RowB = P1^1;
sbit RowC = P1^2;
sbit RowD = P1^3;
sbit C4 = P1^4;
sbit C3 = P1^5;
sbit C2 = P1^6;
sbit C1 = P1^7;*/
sbit rec = P3^0;
sbit RS = P3^7;
sbit RW = P3^3;
sbit E = P3^6;
sbit busy = P2^7;

int main(void)
{

unsigned char cnt=26;
cct_init();
lcd_set();


TMOD = 0x20; //Timer 1 8 bit operation
TH1 = 0x0FD; //Settling the clock for 9600 Baud rate
SCON = 0x50; //Settling on Mode 1 for transfer
TR1=1; // Starting the timer 1
RI=0;



delay(1);
send_sms("AT+CMGF=1\r\n");
delay(1);
send_sms("AT+CMGS=\"+2121212\"\r\n"); // added mob no here
delay(1);
send_sms("ENter MEssage ");
TI=0;
SBUF=cnt;
while(TI==0);
send_sms("\r\n");

TI = 0;
RI = 0;
send_sms("AT\r\n");
delay(10);
send_sms("AT+CMGF=1\r\n");
delay(10);
send_sms("AT+CNMI=2,1,0,0,0\r\n");
TI=0;
RI=0;
write_instruct(0x01);
write_instruct(0x80);
delay(1000);
IE=0x90;
/*
if (RI==1)
{
display_function_lcd("srl Int rec");
delay(100);
writedata(0x01);
}
*/
while(count != 1)
{ //if(RI==1)
//{P1=0x00;}
}
read_message();
while(count!=2){}
rec=1;


return 0;
}


void send_sms(unsigned char *str )
{
int i=0;
while(str!='\0')
{
TI=0;

SBUF=str;
while(TI==0){}

if(TI==1)
{
write_instruct(0x01);
writedata (str);
delay(10);
}

i++;
}

}

void handle_index(void)
{
char ok[]="OK";
char cnmi[]="+CMTI";
int i=0;
int k=0;
int m=0;
char array_buf[20];

display_function_lcd("I m here");
array_buf=SBUF;
i++;
while(1)
{

array_buf=rx0();
if(array_buf=='+')
{
for(k=i;k<=i+4;k++)
{
if(array_buf[k]!=cnmi[m])
{
//writedata(0x01);
//display_function_lcd("Wrong SMS");
}
}
}
display_function_lcd(array_buf);
if (array_buf==',')
{
array_buf[i+1]=index; // extract index from message cnmi
array_buf[i+2]='\0';
count++;
return ;
}
i++;
}
}

void read_message(void)
{
IE=0x00;
send_sms("AT+CMGR=");
TI=0;
SBUF=index; // send sms index
while(TI==0);
send_sms("\r\n");
delay(10);
IE=0x90;
return;
}

char rx0(void)
{
char a;
write_instruct(0x01);
writedata(a);
delay(30);
RI=0;
while(RI==0);
a=SBUF;
return a;
}

void check_response(void)
{


}

void del_msg(void )
{
IE=0x00;
send_sms("AT+CMGD=");

TI=0;
SBUF=index; // send sms index
while(TI==0);
send_sms("\r\n");
delay(10);
IE=0x90;
return;
}
void cct_init(void)
{
P0 = 0x00;
P1 = 0xf0;
P2 = 0x00;
}
void delay(int a)
{
int i,j;
for(i=0;i<a;i++)
{
for(j=0;j<1000;j++){}
}
}
void writedata(char t)
{
busy =1;
lcd_busy();
RW = 0;
RS = 1;
P2 = t;
E = 1;
delay(1);
E = 0;
delay(1);
}


void display_function_lcd(unsigned char *str)
{

int i=0;
while(str!='\0')
{
writedata(str);
i++;
delay(1);
}
write_instruct(0xC0);
delay(2);
return;
}

void lcd_busy(void)
{
RS = 0;
RW = 1;
if(busy==1)
{
E = 0;
delay(50);
E = 1;
}
return;
}


void write_instruct(int z)
{
RW = 0;
RS = 0;
P2 = z;
E = 1;
delay(1);
E = 0;
delay(1);
}

void lcd_set(void)
{

write_instruct(0x38);
delay(2);
write_instruct(0x0E);
delay(2);

write_instruct(0x80);
delay(2);
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…