Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] How to compare received data from UART

Status
Not open for further replies.

kirangkr

Newbie level 6
Joined
Sep 19, 2014
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
183
Hello All
Good Day to you!

In my application I have saved received data from UART to "Rx_reg" array. Now i want to check whether the received data is "DISC" or not. How to do this? Appreciate if you share some sample code for the same. Thank you!

Regards
Kirangkr
 

You can use string compare or you can write program like this

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
char function(void)
{
char string[];
char number[]= "xxxxxxxxxx";
 
for(i = 0; string[i] != 0; i++)
 {
   if(string[i] == num[0])
   {
     for(j = 0; num[j]!= 0; j++)
     if(string[i + j] != num[j])
     break;
   
     if(num[j] == 0)
     return TRUE
   }
}
return FALSE
}

 

The code provided by Venkadesh_M can be used as string compare function and if it returns true. U can switch a LED ON for visual confirmation. Or else u can use same UART and send the same string on UART starting from first character, u will see the string on ur hyper terminal or teraterm. Or u can use alphanumeric LCD to display the strings.

Hope that helps.
 

I presume the above variable number[] should be renamed to num[], otherwise would be nerver used on code.
 

you can go with predefined function strcmp() by placing #include <string.h>
it returns o on success and 1 on fail.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top