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

The SBUF doesnt write the value received into the rcx Array

The code below doesnt work properly when i burn it into the AT89S52 micro controller. From debugging, the Value of SBUF isn't writing into the array. can any tell me what i did wrong?

#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; //this flag is set if end of a string is detected.
bit PBflag; //this flag is set when the MCU gets PB ready message.
bit tr;
unsigned char rxd_cnt = 0; //counts as value are recievced in the serrial ISR.
unsigned char SERIALcase ; //switch case in ISR.
unsigned char *loc;

void main()
{ //INITIALIZATION SCON = 0x50; TMOD = 0x20; TH1 = 0xFD; TR1 = 1; ES = 1; EA = 1; SERIALcase = 1; //set the default of the serial switch case in ISR. PBflag = rxd_cnt = RXDcmpt = 0; //set flag to default.

while(!PBflag) { if(RXDcmpt && !PBflag) //Check if MCU recieved a value confirmPBready(); //Check if its PBready. }

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

//PBready recievd. Proceed with confirguration.

sendAT(txtMOD); tr = OKay(rcx, respOK, sizeof(respOK)); while(!tr); tr = 0; BYTEwrite(0,sizeof(rcx),rcx); //Command "AT+CMGF=1" receives OK

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

//Command AT+CSCS=\"GSM\" receives OK 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; //write the value into address. buffLEN--; //decrement the lenght } return;
}

bit COMP_buff2buff( unsigned char *BUFF1, unsigned char *BUFF2, unsigned char LEN)
{ LEN-=2; while(LEN) { if(LEN ==2) break; if(*BUFF1++ != *BUFF2++) //Check if both value in address are same. return 0; //One value is different.

LEN--; //Decrement. } //AT Last, all values are the same in both buffers.
return 1;
}

void confirmPBready()
{ if( COMP_buff2buff(rcx , PBcheck, sizeof(PBcheck) ) ) //Check if the value recieved is PBready PBflag = 1; //YES. So set flag. return;
}

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

if(RI) { RXD_VAL = SBUF; switch(SERIALcase) { case 1: if(RXD_VAL == 0x0D) {//clear the buffer if the value is 0x0D SERIALcase=2; } break; case 2: if(RXD_VAL == 0x0A) {//clear the buffer if the value is 0x0A SERIALcase = 3; // buffer must receive OD n OA first } break; case 3: //keep recieve till your recieve 0x0D if(RXD_VAL == 0x0D) {//the next character should be 0x0A. SERIALcase = 4; //check for 0x0A. } else { rcx[rxd_cnt++] = RXD_VAL; //save the value recieved in rcx buffer } break; case 4: if(RXD_VAL == 0x0A) {//If 0x0A is recieved after 0x0D, then this is the end of recieve frame. RXDcmpt = 1; //set recieve complete flag. } else { rcx[rxd_cnt++] = RXD_VAL; //save the value recieved in rcx buffer } SERIALcase = 1; //its not 0x0A, so go back to keep recieveing till you detect another 0x0D. 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 Reply Children
No data