Dear Keil Community, I have built a digital thermomter using AT89C52. I have to display the temp on a LCD. The ADC is 10 bits and after coversion routines, i get the hex equivalent of temperature as 368. Now 368 is to be diplayed as 3.406 on LCD. .406 is got as follows: 6/16 = 0.375 8/256= 0.031 Adding 0.375 + 0.031, we get 0.406 Please guide me as to how to do this conversion in C51. Thanks for all the Help.
Let me show you the somewhat crude fixed-point alternative: Hans-Bernhard, did you forget the much fasterfixed-point alternative Erik
You've been shown the straight-forward floating-point method. Let me show you the somewhat crude fixed-point alternative:
fraction = ((unsigned long) (dac_val & 0xff)) * 1000 + 128) / 256
unsigned short rawTemp; /* 10bit ADC value */ float actualTemp; actualTemp = (rawTemp & 0xf00) >> 8; /* scale the units */ actualTemp += ((rawTemp & 0xf0) >> 4)/16 /* scale the 1/16's */ actualTemp += (rawTemp & 0x0f)/256; /* scale the 1/256's */ Or simply:
unsigned short rawTemp; /* 10bit ADC value */ float actualTemp; actualTemp = (rawTemp & 0xf00) >> 8; /* scale the units */ actualTemp += ((rawTemp & 0xf0) >> 4)/16 /* scale the 1/16's */ actualTemp += (rawTemp & 0x0f)/256; /* scale the 1/256's */
unsigned short rawTemp; /* 10bit ADC value */ float actualTemp; actualTemp = rawTemp / 256.0;
Hi, Why not do exactly as you have described the problem? by creating a float variable to store the result. Say something like:-
View all questions in Keil forum