Sign In

Trouble In Displaying Massege On Lcd

navin kumar itsmenk9831@gmail.com

Hardware: AT89S52, GSM (SIM900) Software: C PROGRAM IN KIEL

I AM WORKING ON GSM BASED E-NOTICE BOARD USING AT89S52.
WHEN I SEND MESSAGE THEN LCD DOES NOT DISPLAY THE MESSAGE

CAN U PLEASE PROVIDES THE CODES FOR THIS

Images

Program

#include<reg51.h>
#include<string.h>
#include<absacc.h>
#include<stdlib.h>
#include<ctype.h>
#define buffer 110
					
sbit rs = P3^5;
sbit e = P3^4;

void display_msg();
void delay(unsigned int i);
void lcdstr(unsigned char *s);
void lcdcmd(unsigned char val);
void lcddata(unsigned char val);
void lcdinit();
void tx0(unsigned char);
void SMSString(unsigned char*text) ;
void init();
void clear(void);
void read_notification();
void clear_mybuff();
void delete_msg(void); 
void read_no(unsigned char msg_array[]);
void store_msg(unsigned char msg_array[]);
void password();
void read_nd_check_password(unsigned char msg_array[]);
unsigned char abc,apt=0,count=0;
unsigned char idata msg1[buffer];
unsigned char rec_no[10];
unsigned char time_date[10];
unsigned char code Response[] = "+CMTI";
// Moblie no.of Owner
unsigned char code Mob_no[]= ""; 
unsigned char code Pass_array[]="1234";
unsigned char MyBuff[20], k = 0;
bit flag1=0;
unsigned char store[10];
bit NewMessage = 0;
bit TI_flag = 0;
bit flag=0;
bit No_correct=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)
{      
     
        P1=val;
        rs=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)
{
             
                P1=val;  
                rs=1;
                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 main ()
{

//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=1r"); // 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
//	unsigned char t;
  
	clear();
	lcdinit();
	lcdcmd(0x80);
	lcdstr("Welcome to GSM");
	lcdcmd(0xc0);
	lcdstr("based Noticeboard");

	delay(10);
	init();
IT0 = 1;   // Configure interrupt 0 for falling edge on /INT0 (P3.2)
SMSString("ATr"); // AT commands to initialize gsm modem
delay(50);

SMSString( "ATe0r"); // turn off echo
delay(50);

SMSString( "AT&Wr"); // save settings
delay(50);

SMSString( "AT+CMGF=1r"); // select text mode for sms
delay(50);
  
SMSString( "AT+CNMI=2,1,0,0,0r"); // notification of new sms
while(1)
{
 
IE=0x91;
k=0;
delay(10);
flag=0;
while(!NewMessage);
{
	IE=0X00;
	delay(10);
	NewMessage = 0;
	read_notification(); 
}
//New msg indication.
// +CMTI: "SM",3 
}

}
void read_notification()
{  
	lcdcmd(0x01); //Clear LCD display.
	clear();
	SMSString("AT+CMGR=");
    tx0(MyBuff[12]);
    SMSString("r"); 		
    IE=0x90;
    delay(200);
	read_no(msg1);
	IE=0x00;
	if(No_correct==1)
	{
	
		lcdcmd(0x80);
		lcdstr("Message Received");
		if(!isalpha(msg1[59]))	// checks for received msg is password or a actual msg(data).
		{
			read_nd_check_password(msg1);
		
		}
		else
			{
    			store_msg(msg1);
				password();
				flag1=1;
			}
	}
	else
	{
		lcdcmd(0x01);
		lcdcmd(0x80);
		lcdstr("Msg frm Unknown");
		delay(1);
	}
	clear();

if(MyBuff[12]>='9')	//After 9 msgs recieved it clears the Msg index from SIM
{
	delete_msg();
}

clear_mybuff();

return;
}

void read_nd_check_password(unsigned char msg_array[])
{
if(Pass_array[0]==msg_array[59]&&
	Pass_array[1]== msg_array[60]&&
	Pass_array[2]==msg_array[61]&&
	Pass_array[3]== msg_array[62])
	{
		display_msg();
	}
	else
	{	
	SMSString("AT+CMGS="");
	SMSString(Mob_no);
	SMSString(""r");
	delay(1);
	SMSString("Password Incorrect!!");
	tx0(0x1A); // Ctrl+z
	delay(10);	
	}
return;
}
void password()
{
	SMSString("AT+CMGS="");
	SMSString(Mob_no);
	SMSString(""r");
	delay(1);
	SMSString("Send Your 4 Digit Password");
	tx0(0x1A); // Ctrl+z
	delay(10);	
return;
	}

void store_msg(unsigned char msg_array[])
{
unsigned char i,j;
i=59;
j=0;
	while(msg_array[i]!='r')
	{
	 	store[j]= msg_array[i];
		i++;
		j++;
	}
return;
}

void display_msg()
{
	lcdcmd(0x01);
	lcdcmd(0x80);
	lcdstr("Received Msg");
	delay(1);
	lcdcmd(0xc0);
	lcdstr(store);
return;
}
void delete_msg(void)
{
	SMSString("AT+CMGD=9r");
	delay(1);
	SMSString("AT+CMGD=8r");
	delay(1);
	SMSString("AT+CMGD=7r");
	delay(1);
	SMSString("AT+CMGD=6r");
	delay(1);
	SMSString("AT+CMGD=5r");
	delay(1);
	SMSString("AT+CMGD=4r");
	delay(1);
	SMSString("AT+CMGD=3r");
	delay(1);
	SMSString("AT+CMGD=2r");
	delay(1);
	SMSString("AT+CMGD=1r");
	delay(1);
	return;
}

void init()
{
P0=0x00;
	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] = '';
            	NewMessage = 1;
                k = 0; 
            }
       }	   
	   	else 
	   	{
			msg1[abc]=ch;//received msg is stored.
			abc++;
       		k = 0;
       	}
       } 
}

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;
		abc=0;
}

void read_no(unsigned char msg_array[])	  // reads the no from received msg and compares it with stored msg, If found wrong then send a msg to owner.
{
unsigned char i;
	if(Mob_no[0]==msg_array[23]&&
	Mob_no[1]== msg_array[24]&&
	Mob_no[2]==msg_array[25]&&
	Mob_no[3]== msg_array[26]&&
	Mob_no[4]==msg_array[27]&&
	Mob_no[5]== msg_array[28]&&
	Mob_no[6]==msg_array[29]&&
	Mob_no[7]== msg_array[30]&&
	Mob_no[8]==msg_array[31]&&
	Mob_no[9]== msg_array[32])
	{
		No_correct=1;
	}
	else	// Sends a msg to stored no if some unauthoriesd tries to send a msg.
	{
	 		No_correct=0;
			SMSString("AT+CMGS="");
			SMSString(Mob_no);
			SMSString(""r");
			delay(1);
			SMSString("Msg from Unknown number:( ");
			for(i=23;i<=32;i++)
			{
			tx0(msg_array[i]);
			delay(0);
			}
			SMSString(") is received.");
				tx0(0x1A); // Ctrl+z
			delay(100);	
	}
return;
}

Post a reply to navin kumar

Think you can help navin kumar ? Then post your thoughts that might help navin kumar. You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.