Microcontroller › 8051 › Gsm based eNoticeboard
- This topic has 1 reply, 2 voices, and was last updated 12 years ago by AJISH ALFRED.
-
AuthorPosts
-
October 3, 2012 at 7:10 pm #1979sonuParticipant
i designed this code as reception of SMS on Modem n get print over a LCD, there is some error when msg recived and have to be print over LCD, please assist something where is the bug…
my code is plz suggest something where is the fault
#include
sbit RS=P3^7;
sbit EN=P3^5;
sbit RW=P3^6;
sbit BZ=P3^4;
sbit BZ1=P3^3;
#define LCD_PORT P2
//
// Forward function declaration
//
unsigned char Rxmsg(void);
void lcdinit(void);
void lcdData(unsigned char l);
void lcdcmd(unsigned char k);
void DelayMs(unsigned int count);
void InitModem(void);
void initdisplay(void);
code unsigned char msg[25]="Welcome to eNotice Board";
//
// Main rotine
//
void main()
{ RW=0;
TMOD=0x20; // Configure UART at 9600 baud rate
TH1=0xFD;
SCON=0x50;
TR1=1;lcdinit(); // Initialize LCD
initdisplay();
DelayMs(5000);
while(1)
{
InitModem();
Rxmsg();
}
}
//
// Modem initialization subroutine
//
void InitModem(void) // "a", 'a'
{unsigned int j=0;
unsigned char i=0,k=0;
unsigned char a[]="at+cmgf=1";
//unsigned char b[]="at+cpms="ME","ME","ME"" ;
unsigned char c[]="at+cmgd=" ;
unsigned char d[6];ReInit:
for(i=0;i<6;i++)
d=0x00;i=0;
while(a!=' ')
{SBUF=a;
while(TI==0); // ATE0 sending to turn off the echo
TI=0;
lcdData(a);
i++;}lcdData(' '); // Enter
SBUF=0x0d;
while(TI==0);
TI=0;for(i=0;i<4;i++) //command to recv data
{j=0;
while(RI==0)
{if(j>=1000)
goto ReInit;
DelayMs(1);
j++;
}
d=SBUF;
RI=0;
lcdData(d);
}for(i=0;i<4;i++) //command to compare data
{if((d=='E') || (d=='R'))
goto ReInit;
if((d=='O') || (d=='K'))
goto InitS;}InitS:
for(k=0;k<10;k++)
{for(i=0;i<6;i++)
d=0x00;lcdcmd(0x01);
DelayMs(10);
lcdcmd(0x80);
DelayMs(10);i=0;
while(c!=' ')
{SBUF=c;
while(TI==0); // sending AT+CMGD to delete message
TI=0;
lcdData(c);
i++;}lcdData(k + 0x30); // Enter
SBUF=k + 0x30;
while(TI==0);
TI=0;lcdData(' '); // Enter
SBUF=0x0d;
while(TI==0);
TI=0;for(i=0;i<5;i++) //command to recv data
{j=0;
while(RI==0)
{
if(j>=1000)
goto ReInit;
DelayMs(1);
j++;
}
d=SBUF;
RI=0;
lcdData(d);
}
DelayMs(100);
}
//return 0;
}//
// Recieve message subroutine
//
unsigned char Rxmsg(void)
{unsigned char i=0,ret=0;
unsigned int j=0;
unsigned char c[90];
unsigned char d[6];retry:
lcdinit();
lcdcmd(0x80);
DelayMs(10);while(msg!=' ')
{
lcdData(msg);
lcdcmd(0x18);
DelayMs(500);
i++;
}for(i=0;i<16;i++)
{
lcdData(' ');
lcdcmd(0x18);
DelayMs(400);
}for(i=0;i<90;i++)
c=0x00;for(i=0;i<6;i++)
d=0x00;
for(i=0;i<4;i++) //command to recv data
{
j=0;
while(RI==0)
{
if(j>=1000)
goto retry;
DelayMs(1);
j++;
}
d=SBUF;
RI=0;
lcdData(d);
}for(i=0;i<5;i++)
d=0x00;
for(i=0;i<4;i++) //command to compare data
{
if((d=='E') || (d=='R'))
return ret;
if((d=='+') || (d=='C')|| (d=='M')) // message recieved
goto sucess;
}sucess:
BZ1=0;
DelayMs(100);
SBUF='a';
while(TI==0);
TI=0;SBUF='t';
while(TI==0);
TI=0;SBUF='+';
while(TI==0);
TI=0;SBUF='c';
while(TI==0);
TI=0;SBUF='m';
while(TI==0);
TI=0;SBUF='g';
while(TI==0);
TI=0;SBUF='r';
while(TI==0);
TI=0;SBUF='=';
while(TI==0);
TI=0;SBUF='1';
while(TI==0);
TI=0;SBUF=0x0d;
while(TI==0);
TI=0;DelayMs(100);
for(i=0;i<90;i++)
{
j=0;
while(RI==0)
{
if(j>=1000)
goto timeout;
DelayMs(1);
j++;
}
c=SBUF;
RI=0;
}
BZ1=1;
timeout:for(i=0;i<5;i++) //command to recv data
{
if((c=='E') || (c=='R'))
return ret;
}for(i=0;i<92;i++)
{
if((c=='1') && (c[i+1]=='2') && (c[i+2]=='3')&& (c[i+3]=='4') && (c[i+4]=='5') )
goto sucess1;
if((c=='D') && (c[i+1]=='E') && (c[i+2]=='L'))
goto delete;
}/*
sucess1:
for(;i<92;i++)
{
if((c=='1') && (c[i+1]=='2') && (c[i+2]=='3')&& (c[i+3]=='4') && (c[i+4]=='5') )
goto sucess2;
}
goto delete; */sucess1:
BZ=0;
lcdcmd(0x01);
lcdcmd(0x84);
DelayMs(1000);
BZ=1;i=i+5;
j=0;
while(c[i+4]!='O' && c[i+5]!='K')
{
//msg[j]=c;
lcdData(c);
DelayMs(100);
i++;
j++;
}
//msg[j]=' ';delete:
for(i=0;i<90;i++)
{
c=0x00;
}SBUF='a';
while(TI==0);
TI=0;SBUF='t';
while(TI==0);
TI=0;SBUF='+';
while(TI==0);
TI=0;SBUF='c';
while(TI==0);
TI=0;SBUF='m';
while(TI==0);
TI=0;SBUF='g';
while(TI==0);
TI=0;SBUF='d';
while(TI==0);
TI=0;SBUF='=';
while(TI==0);
TI=0;SBUF='1';
while(TI==0);
TI=0;SBUF=0x0d;
while(TI==0);
TI=0;for(i=0;i<5;i++) //command to recv data
{
j=0;
while(RI==0)
{
if(j>=1000)
goto delete;
DelayMs(1);
j++;
}
c=SBUF;
RI=0;
}return ret;
}//
// Lcd initialization subroutine
//
void lcdinit(void)
{
lcdcmd(0x38);
DelayMs(250);
lcdcmd(0x0C);
DelayMs(250);
lcdcmd(0x01);
DelayMs(250);
lcdcmd(0x06);
DelayMs(250);
lcdcmd(0x80);
DelayMs(250);
}//
// Lcd data display
//
void lcdData(unsigned char l)
{
LCD_PORT=l;
RS=1;
EN=1;
DelayMs(1);
EN=0;
return;
}//
// Lcd command
//
void lcdcmd(unsigned char k)
{
LCD_PORT=k;
RS=0;
EN=1;
DelayMs(1);
EN=0;
return;
}//
// Delay mS function
//
void DelayMs(unsigned int count)
{ // mSec Delay 11.0592 Mhz
unsigned int i; // Keil v7.5a
while(count) {
i = 115; // 115 exact value
while(i>0) i--;
count--;
}
}void initdisplay(void)
{
unsigned char d=0,a[]=" SMS Based",c[]=" Notice Board";
lcdcmd(0x01);
lcdcmd(0x80);
while(d!=15)
{
lcdData(a[d]);
d++ ;
}lcdcmd(0xc0);
DelayMs(10);
d=0;
while(c[d]!=' ')
{
lcdData(c[d]);
d++;
}
}October 24, 2012 at 4:35 pm #8686AJISH ALFREDParticipantHi Sonu,
No one would be interseted to go through such a code post. Please make it more comfortable to read.
-
AuthorPosts
- You must be logged in to reply to this topic.