[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
Visit site
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.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…