Hi,
Most "compare" act like a "subtract" .... thus be sure to use the correct variable type and size.
But there is an issue:
(I alwas recommend to use a paper and a pencil to test your function. I doubt you did this)
You say"
If A = B, ok don't do anything in C
If A+5 > B, increase C
If A-5 < B, decrease C
But this is contradicting.
Lets say A = 3, B = 3;
Compare 1) Then A = B is TRUE --> do nothing
But
Compare 2) A + 5 > B --> 3 + 5 > 3 --> 8 > 3 is TRUE, too.
And
Compare 3) A - 5 < B --> 3 - 5 < 3 --> -2 < 3 is TRUE, too.
(Mind the negative value of '-2' here. A "signed compare" will be TRUE, while an "unsigned compare" will treat -2 as 254 and thus will be FALSE)
So all three compares are TRUE at the same time.
Now it depends on how you process the three compares (if one compare was "true", do you process the following compares or not?)
and how you define "do nothing" ( is "increase C" followed by a "decrease C" a "do nothing" or rather a "do both"? Just focussed on the value of "C" it does not matter, but it matters in processing time and if there anything else is done - also have in mind that maybe half a year later you add some code... )
Generally you never do a compare that - when TRUE - does nothing....you don't need to tell a microcontroller "to do nothing".
You rather do a compare that when "true" does something .... (and it automatically does nothing when FALSE)
Klaus