In the code below, if BAUD_RATE1 and DESIRED_RATE are equal then both parts of the 'if' are executed. As, in those circumstances, both parts set BAUD_ERR1 to zero it does not cause a problem but it worries me that I don't understand why this code does that.
All variables are uint32_t, and the code is written for XC8
All variables are uint32_t, and the code is written for XC8
Code:
if (BAUD_RATE1 >= DESIRED_RATE)
{
BAUD_ERR1 = (PP100K*(BAUD_RATE1-DESIRED_RATE)/DESIRED_RATE);
}
else
{
BAUD_ERR1 = (PP100K*(DESIRED_RATE-BAUD_RATE1)/DESIRED_RATE);
}