Discussion in "PIC Microcontroller Discussion" started by    pravin_35    Aug 29, 2015.
Sat Aug 29 2015, 01:55 pm
#1
Hi every one ,

I need a help how to compare the Usart receive data with constant String...

CODE:
 
char *data=USARTReadData();
if(strcmp(data,"Start")==0)
     {
     PORTCbits.RC4 = 0;
         }
  else
      {
          PORTCbits.RC4 = 1;
        }
 


the Port doesn't get toggled..
Mon Aug 31 2015, 12:14 pm
#2
can you provide code for "USARTReadData();" I doubt it will be returning you a string. from first thought I believe it should just return a character not a string.
Mon Aug 31 2015, 12:15 pm
#3
Thu Sep 10 2015, 01:50 pm
#4


can you provide code for "USARTReadData();" I doubt it will be returning you a string. from first thought I believe it should just return a character not a string.

ajay_bhargav



char USARTReadData()
{
    char data;

    //Check if q is empty
    if(UQFront==-1)
	return 0;

    data=URBuff[UQFront];

    if(UQFront==UQEnd)
    {
        //If single data is left
	//So empty q
	UQFront=UQEnd=-1;
    }
    else
    {
	UQFront++;

	if(UQFront==RECEIVE_BUFF_SIZE)
            UQFront=0;
    }

    return data;
}
Fri Sep 11 2015, 02:31 am
#5
The first problem is that USARTReadData() returns a char or 0 (NULL)
and you use it as a char * , the address of a string.
I'm surprised you have not had errors of some sort.

What system are you writing for ?




 pravin_35 like this.
Tue Sep 15 2015, 07:16 pm
#6



What system are you writing for ?

ExperimenterUK



Pic16f886 Xc8 compiler
Wed Sep 30 2015, 02:57 am
#7
I am not sure you've solved it or not but "USARTReadData" only returns a byte not a string. so you first need to store data into a buffer until you get a \r or \n. for e.g.
 char buffer[30];
char I, ch;

I = 0;
do {
    ch = USARTReadData();
    if ((ch == '\r') || (ch == '\n')) {
        buffer[I++] = '\0';
        break;
    }
    if (I == 29)  {
        buffer[I] = '\0';
        break;
    }
} while (1);
// Now you buffer has received a string you can process it as you want
 pravin_35 like this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am