sachinkp21587
Member level 2

- Joined
- Mar 15, 2010
- Messages
- 51
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Location
- india (U.P.)
- Activity points
- 1,703
i am facing problem in string compare. i am always finding it unequal. can anybody please sort out this. i have really tried a lot but cant find the solution.
#include <regx51.h>
#include <string.h>
void init_rs232_tx(void);
void tx_data(unsigned char );
void display_tx(unsigned char[]);
unsigned char rx_data(void);
unsigned char chk_response(unsigned char [3]);
unsigned char n_ip[15] = 0;
unsigned char input_port[4];
void main(void)
{
unsigned char ip_en = 8,i=0,op_en = 1;
init_rs232_tx();
debug:
display_tx("+++*");
if(chk_response("<E>"))
goto debug;
void init_rs232_tx(void)
{
P3 = 0XFF;
TMOD = 0x20;
TH1 = -3;
SCON = 0x50;
TR1 = 1;
}
unsigned char rx_data(void)
{
unsigned char a=0;
while(RI == 0);
a = SBUF;
RI = 0;
return a;
}
unsigned char chk_response(unsigned char response[])
{
unsigned char n_data[3],i=0;
for(i=0;i<3;i++)
{
again:
n_data = rx_data();
if(n_data[0] != response[0])
goto again;
}
if(strcmp(n_data,response) == 0)
return 0;
else
return 1;
}
when i am using following function instead of above thn the string seems to be equal to microcontroller.
unsigned char chk_response(unsigned char response[])
{
unsigned char n_data[3] = "<E>",i=0;
if(strcmp(n_data,response) == 0)
return 0;
else
return 1;
}
i am not getting why is it behaving like this.
thanks in advance
#include <regx51.h>
#include <string.h>
void init_rs232_tx(void);
void tx_data(unsigned char );
void display_tx(unsigned char[]);
unsigned char rx_data(void);
unsigned char chk_response(unsigned char [3]);
unsigned char n_ip[15] = 0;
unsigned char input_port[4];
void main(void)
{
unsigned char ip_en = 8,i=0,op_en = 1;
init_rs232_tx();
debug:
display_tx("+++*");
if(chk_response("<E>"))
goto debug;
void init_rs232_tx(void)
{
P3 = 0XFF;
TMOD = 0x20;
TH1 = -3;
SCON = 0x50;
TR1 = 1;
}
unsigned char rx_data(void)
{
unsigned char a=0;
while(RI == 0);
a = SBUF;
RI = 0;
return a;
}
unsigned char chk_response(unsigned char response[])
{
unsigned char n_data[3],i=0;
for(i=0;i<3;i++)
{
again:
n_data = rx_data();
if(n_data[0] != response[0])
goto again;
}
if(strcmp(n_data,response) == 0)
return 0;
else
return 1;
}
when i am using following function instead of above thn the string seems to be equal to microcontroller.
unsigned char chk_response(unsigned char response[])
{
unsigned char n_data[3] = "<E>",i=0;
if(strcmp(n_data,response) == 0)
return 0;
else
return 1;
}
i am not getting why is it behaving like this.
thanks in advance