Perhaps I am overlooking a limitation of this PIC chip, but want to confirm.
I am compiling with HiTech C.
I have a routine that multiplies the 8 bit counter (TMR0) by the number 139 (fixed point math for .0139). the LCDwrite function converts to a string and adjusts the decimal place to convert back from the fixed point notation, then outputs the value to my LCD.
However, although I am setup to do this all in LONG format. The resulting multiplication seems to be of data type INT.
To exemplify:
works fine until I get to a value over 32767, at which point the LCD displays a negative number. However:
Will display just fine. Additionally:
Fixes the issue.
I would like to get to the root of this problem so I can avoid it in the future.
Thank you
I am compiling with HiTech C.
I have a routine that multiplies the 8 bit counter (TMR0) by the number 139 (fixed point math for .0139). the LCDwrite function converts to a string and adjusts the decimal place to convert back from the fixed point notation, then outputs the value to my LCD.
However, although I am setup to do this all in LONG format. The resulting multiplication seems to be of data type INT.
To exemplify:
Rich (BB code):
long result
result=TMR0*139;
LCDwrite(result)
Rich (BB code):
long result
result=TMR0*139;
result=35306; //(255*139=35306)
LCDwrite(result)
Rich (BB code):
long result
result=TMR0*100;
result=result+TRM0*39;
LCDwrite(result)
I would like to get to the root of this problem so I can avoid it in the future.
Thank you