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

problem in serial communication

HI guys,

My project is about switching on and off of motor by sms control..
I tried to check whether my controller is working fine or not using simple blinking of LED program , its working good, no problem with oscillator and reset switch part... everythng is fine but when i try for serial programming i am not getting the output.. I checked my gsm modem using hyperterminal its working fine.but its not working with 8051.

below is my code

#include <reg51.h>
void init (void); // prototype declaration
void Uart_gsm (void);
void delay(unsigned char);
void Recievedata();
void gsminit(void);
void gsmcmdsend(unsigned char *); unsigned char Rx_data(void); unsigned char message[11]; unsigned char count; unsigned char code password1[10]="device1 on"; // Commands for controlling devices unsigned char code password2[11]="device1 off";

void main()
{ // port initialization

init();
Uart_gsm(); // serial port initialization
gsminit();
Recievedata(); // for recieving the data from modem
}

void init(void) { P2 = 0xFF; }

void Uart_gsm(void)
{ TMOD = 0x20;
TH1 = 0xFD;
SCON = 0X50;
TR1 = 1;
} void serial_put(char c)
{ do{}while(!TI); TI=0; SBUF=c;
}

void sms(void) //sending pump is on
{ char t5[]={'A','T','+','C','M','G','S','=','"','+','9','1','9','1','7','6','3','6','6','4','9','6','"'} ;
char t7[]="PUMP IS ON";
unsigned int i;
delay(1000);
gsmcmdsend(t5); for(i=0;t7[i];i++)serial_put(t7[i]); do{}while(!TI); TI=0; SBUF=0x1A;
delay(20000);
}

void Recievedata()
{ unsigned int count,count1,i; while(1) { while(Rx_data()!='+'); // checking message format while(Rx_data()!='C'); while(Rx_data()!='M'); while(Rx_data()!='T'); while(Rx_data()!=':'); while(Rx_data()!='"'); while(Rx_data()!='\n');
for(count=0;count<11;count++) // storing msg in a buffer
{ message[count]=Rx_data();
if(message[count]=='\r')
break;
} message[count]='\0';

for(i=0;i<10;i++) //verifying message
{ if(message[i]==password1[i]) count++;
} if(count==10)
{ P2 = 0x00;
sms();
}

for(i=0;i<11;i++)
{ if(message[i]==password2[i]) count1++;
}

if(count1==11)

{
P2 = 0xFF;
}

} }
// TO RECIEVE SERAIL DATA
unsigned char Rx_data(void)
{ RI=0;
while(RI==0);
return(SBUF);
}

void delay(unsigned char x)
{ unsigned int i,j; for(i=0;i<x;i++) for(j=0;j<2000;j++); }

void gsminit(void)
{ // AT COMMANDS
unsigned char gsm_cmd1[]="AT";
unsigned char gsm_cmd2[]="ATE0";
unsigned char gsm_cmd3[]="AT&W";
unsigned char gsm_cmd4[]="AT+CMGF=1";
unsigned char gsm_cmd5[]="AT+CNMI=2,2,0,0,0";
gsmcmdsend(gsm_cmd1);
gsmcmdsend(gsm_cmd2);
gsmcmdsend(gsm_cmd3);
gsmcmdsend(gsm_cmd4);
gsmcmdsend(gsm_cmd5);
}

void gsmcmdsend(unsigned char *cmd)
{ unsigned char i;
for(i=0;*cmd!='\0';i++)
{ SBUF=*cmd; while(TI==0); TI=0; cmd++; } delay(2); SBUF=0x0A; while(TI==0); TI=0; SBUF=0x0D; while(TI==0); TI=0; while(RI==0); RI=0; }

I complied this program using KEIL complier , 0 errors and 0 warnings.

After switching On the supply, port 2 goes high..i dont whats the problem with my circuit.. :sad: