Discussion in "PIC Microcontroller Discussion" started by    pravin_35    Aug 29, 2015.
Sat Aug 29 2015, 08:25 AM
#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, 06:44 AM
#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, 06:45 AM
#3
Thu Sep 10 2015, 08:20 AM
#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;
}
Thu Sep 10 2015, 09:01 PM
#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, 01:46 PM
#6



What system are you writing for ?

ExperimenterUK



Pic16f886 Xc8 compiler
Tue Sep 29 2015, 09:27 PM
#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

Conversation

No messages yet.

Downloads

Comments

Mirza123
Thu Jun 25 2020, 03:46 PM
eunicelove124
Mon Jun 22 2020, 03:03 PM
cerouno
Tue Jun 16 2020, 05:10 PM
Marce
Sat Jun 13 2020, 09:43 PM
Davidthils
Thu May 21 2020, 12:44 PM
Jakeror
Thu May 21 2020, 01:28 AM
motorCar
Wed May 20 2020, 07:05 PM
Vordrync
Wed May 20 2020, 11:52 AM

Online

Guests: 90, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38215
Newest member: Mirza123