@spinnaker
Keep in mind that when you read the CCP registers, you get two unsigned integers (16 bit). When you subtract them, you get a 2's compliment result but the compiler still treats that result as unsigned. I'm not real sure how XC8 would take casting this to a signed value (it's fussy about such things) but you'll need to do that to be able to complement that arithmetically. HitechC didn't mind.
I'll do some poking around on it..
EDIT2: Disregard. Math is wrong.. Writing C, thinking assembler. Grr,
Keep in mind that when you read the CCP registers, you get two unsigned integers (16 bit). When you subtract them, you get a 2's compliment result but the compiler still treats that result as unsigned. I'm not real sure how XC8 would take casting this to a signed value (it's fussy about such things) but you'll need to do that to be able to complement that arithmetically. HitechC didn't mind.
I'll do some poking around on it..
EDIT2: Disregard. Math is wrong.. Writing C, thinking assembler. Grr,
Last edited: