Hi Scott,
If statements always assume that the number is positive. 0-65535 for words. So, "IF X < 0 then" will never return true.
There are several ways to deal with it.
One is to just see if virtual_ground is greater than adval. If it is then the subtraction will create a negative number so reverse the subtraction (virtual_ground - adval).
Another is to just go ahead and do the subtraction then test bit15 to see if it ended up being a negative number or not. If it did, use ABS() to get the absolute value.
1 more, subtract the two numbers and use the SDEC modifier for LCDOUT or SEROUT2 to display the negative number.
If you need to do any multiplication or division with the result, then it can't be negative. Only add and subtract will work with negative numbers.
<br>
Bookmarks