
Subtract 1920, and you'll get the correct -2381.Īs long as you're certain that DELTAC and DELTA will never contrive to yield a result smaller than -32768, this is all you'll need to do to keep everything kosher. Divide that by 255, and you'll get the correct -461.

So the first thing you need to do is redefine DELTAC as a signed short, rather than an unsigned short. Printf is looking for an int (16-bit value) therefore the value 120980 (0x1D894) will be truncated to 0xD894, which, interpreted as a signed int, is equal to -(0x276C) or -10092. Therefore, that 0xFF0B is going to be interpreted as the positive value 65291. The compiler knows that DELTAC is an unsigned number, therefore it cannot possibly be negative. However, it's going to come back to haunt you soon. At this point, that is harmless - it's just going to put the hex value 0xFF0B in memory. Now, you're storing a negative number in it. I'm not sure if it is an popular compiler, or if it was a good choice. The CodeVisionAVR is an IDE and has a chip programmer that works with the STK500 kit, which I'm using. I liked to have some sort of an IDE, so I didn't need to enter long command lines for compilation. Some background about my choice of CVAVR.

I hope I don't have to change to another compiler again?

Gives -10092 instead of the desired -2381 Then, I came accross the same problems again, and I don't know how to work around this one: Thanks to Bob and all other people who respondedn and try to help me.
