# HG changeset patch # User Ethan Zonca # Date 2014-11-22 16:30:15 # Node ID 89dc4e02c836f5324a3d3ae31a7f93761d7d8cf5 # Parent 8ad61315d68de74e54f5f0044bec4bce60956ecc Sketchy remainder fixing for fahrenheit support diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -85,7 +85,7 @@ CDEFS+=-DHSE_VALUE=8000000 #EMZ Optimized: -MCUFLAGS=-mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections +MCUFLAGS=-mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -mfloat-abi=soft # Default: MCUFLAGS=-mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections diff --git a/main.c b/main.c --- a/main.c +++ b/main.c @@ -142,7 +142,7 @@ int main(void) } // Read temperature and update global temp vars -int16_t temp = 0; +int32_t temp = 0; uint8_t temp_frac = 0; void update_temp() { @@ -181,10 +181,15 @@ void update_temp() { } if(temp_units == TEMP_UNITS_FAHRENHEIT) { - temp *= 10; // fixed point mul by 1.8 - temp *= 18; - temp /= 100; + temp *= 9; // fixed point mul by 1.8 + temp /= 5; temp += 32; + + temp_frac *= 9; + temp_frac /= 5; + temp_frac += 32; + temp += temp_frac/100; // add overflow to above + temp_frac %= 100; } }