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

Sat Feb 01 2020, 10:12 AM
Pearl Olin
Hello,
Wed Jan 22 2020, 06:16 PM
MINU CHAUDHARY
I m getting errors while simulation process during interfacing socket output and lcd... Can i get the report of ur project which is same as us.
Tue Jan 14 2020, 07:08 AM
shubham kharade
when i am trying to simulate the program in Proteus 8 professional, I am getting some errors as cannot find module file dhtxx.md can u help me
Tue Dec 17 2019, 01:44 PM
Devangi
hello..i am programming industrial timer using 8051 with 24lc64 eeprom. i have query in storing the 3 diff value in eeprom with enter button. can anyone share c code ?
Tue Dec 17 2019, 10:30 AM
Andrius
Hello. Can anyone share the code in Bascon and scheme in Proteus?
Thu Nov 21 2019, 12:30 PM
raj2555
how to interface 8051 microcontroller with NRF24L01+ module
ExperimenterUK
Sat Oct 12 2019, 10:23 PM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 10:18 AM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 07:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 08:48 PM
Caryn Kover
Thank you for your time,

Downloads

Comments

arun.sapro
Wed Feb 12 2020, 04:47 PM
prathmiyer
Tue Feb 11 2020, 11:12 AM
Just4Fun
Sat Feb 01 2020, 01:29 PM
Deepkumar
Thu Jan 30 2020, 03:52 PM
wounder
Sat Jan 25 2020, 12:09 PM
brucewilliams20
Thu Jan 23 2020, 11:47 AM
Nippy56
Sun Jan 19 2020, 02:13 AM
usb5962
Sat Jan 11 2020, 10:42 AM

Online

Guests: 36, Members: 0 ...

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

Members: 38122
Newest member: arun.sapro
Forum Activity
wounder Avatar
Posted By wounder
Mon Feb 10 2020, 08:32 AM
From below sample code for nuvoton 8051 timer0 mod...
Just4Fun Avatar
Posted By Just4Fun
Sat Feb 01 2020, 02:20 PM
If you want to use a CH55x MCU there isn't any adv...
Just4Fun Avatar
Posted By Just4Fun
Sat Feb 01 2020, 01:51 PM
Hi all,I was curious to try out the CH552 MCU (805...
Deepkumar Avatar
Posted By Deepkumar
Thu Jan 30 2020, 05:36 PM
I want to send a text message in other than the En...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Jan 26 2020, 04:05 AM
For a 12MHz crystal using a normal divided by 12 c...
wounder Avatar
Posted By wounder
Sat Jan 25 2020, 12:14 PM
I have a 8051 micro controller ,it has timer0,1,2,...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jan 17 2020, 10:24 PM
We will need the circuit diagram.A Proteus simulat...
Billz Avatar
Posted By Billz
Sat Jan 11 2020, 05:43 PM
hi everyone please attached files are my c code fo...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jan 07 2020, 08:18 PM
Not a stupid question.Setting up "Eclipse" can be...
elt Avatar
Posted By elt
Tue Jan 07 2020, 07:06 PM
So i have just began learning programming micros a...