This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Please help me with my code. It does nothing when i burn the code into the AT89S52 mc.

I use AT89S52 Mc (MicroController) and Neoway M590E GSM module. when i burn the code into the Mc. i don't get any message to the number specified the code. kindly help me.
thanks a lot in advance.

#include <reg51.h>

void confirmPBready(void);
void BYTEwrite( unsigned char VAL, unsigned char buffLEN, unsigned char *buffADDR);
void sendAT(unsigned char *buf);
bit COMP_buff2buff( unsigned char *BUFF1, unsigned char *BUFF2, unsigned char LEN);
void delay(void);
bit OKay( unsigned char *BUFF1, unsigned char *BUFF2, unsigned char LEN);

unsigned char rcx[13];
code char txtMOD[]="AT+CMGF=1";
code char TE_com[]="AT+CSCS=\"GSM\"";
xdata unsigned char GSMRESPONSE[]="AT+CMGS=\"+2349056777712\"";
unsigned char respOK[] = "OK";
unsigned char PBcheck[]="+PBREADY";
bit RXDcmpt;
bit PBflag;
bit tr;
unsigned char  rxd_cnt = 0;
unsigned char SERIALcase ;
unsigned char *loc;




void main()
{
        //INITIALIZATION
        SCON = 0x50;
        TMOD = 0x20;
        TH1 = 0xFD;
        TR1 = 1;
        ES = 1;
        EA = 1;
        SERIALcase = 1;
        PBflag = rxd_cnt = RXDcmpt = 0;

        while(!PBflag)
        {
                if(RXDcmpt && !PBflag)
                confirmPBready();
        }

        BYTEwrite(0,sizeof(rcx),rcx);   //clear buffer

        sendAT(txtMOD);
        tr = OKay(rcx, respOK, sizeof(respOK));
        while(!tr);
        tr = 0;
        BYTEwrite(0,sizeof(rcx),rcx);


        sendAT(TE_com);
        tr = COMP_buff2buff(rcx, respOK, sizeof(respOK));
        while(!tr);
        tr = 0;
        BYTEwrite(0,sizeof(rcx),rcx);


                sendAT(GSMRESPONSE);
                delay();
                sendAT("GSM MODULE TEXT VIA CODING");
                delay();
                sendAT("0x1A");
}

void delay(void)
{
unsigned int i;
for(i=0;i<25000;i++);
}

void BYTEwrite( unsigned char VAL, unsigned char buffLEN, unsigned char *buffADDR)
{
while(buffLEN)
{
*buffADDR++ = VAL;
buffLEN--;
}
return;
}

bit COMP_buff2buff( unsigned char *BUFF1, unsigned char *BUFF2, unsigned char LEN)
{
LEN-=2;
while(LEN)
{
if(LEN ==2)
break;
if(*BUFF1++ != *BUFF2++)
return 0;

LEN--;
}
return 1;
}

void confirmPBready()
{
if( COMP_buff2buff(rcx , PBcheck, sizeof(PBcheck) ) )
PBflag = 1;
return;
}

void serial(void) interrupt 4
{
unsigned char RXD_VAL;
RXD_VAL = SBUF;

if(RI)
{
switch(SERIALcase)
{
case 1:
if(RXD_VAL == 0x0D)
{
SERIALcase=2;
}
break;
case 2:
if(RXD_VAL == 0x0A)
{
SERIALcase = 3;
}
break;
case 3:
if(RXD_VAL == 0x0D)
{
SERIALcase  = 4;
}
else
{
rcx[rxd_cnt++] = RXD_VAL;
}
break;
case 4:
if(RXD_VAL == 0x0A)
{
RXDcmpt = 1;

}
else
{
rcx[rxd_cnt++] = RXD_VAL;
}

SERIALcase  = 1;
break;
}
}
RI = 0;
}


void sendAT(unsigned char *buf)
{
        while(*buf)
        {
                SBUF = *buf++;
                while(!TI);
                TI=0;
        }
        SBUF = 0x0D;
        while(!TI);
        TI=0;
}

bit OKay( unsigned char *BUFF1, unsigned char *BUFF2, unsigned char LEN)
{
 while(LEN)
 {
  if(*BUFF1++ != *BUFF2++) //Check if both value in address are same.
   return 0;              //One value is different.
   LEN--;               //Decrement.
}
return 1;       //AT Last, all values are the same in both buffers.
}

Parents
  • So the OP has two names.

    "Same" code as in
    http://www.keil.com/forum/62115/

    But then posted using the name "Garuba Malik".

    And most of the source code comments got deleted in the new post.

    So maybe the OP didn't reaquire source code from the editor and instead manually tried to restore the original post to usable state - an obviously quite bad thing to try.

    Another thing - tabs aren't working so very well when posting source code. Tab size doesn't mean much in a web browser.

Reply
  • So the OP has two names.

    "Same" code as in
    http://www.keil.com/forum/62115/

    But then posted using the name "Garuba Malik".

    And most of the source code comments got deleted in the new post.

    So maybe the OP didn't reaquire source code from the editor and instead manually tried to restore the original post to usable state - an obviously quite bad thing to try.

    Another thing - tabs aren't working so very well when posting source code. Tab size doesn't mean much in a web browser.

Children