This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Multiplication Help Wanted!!

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.

Parents
  • 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 / 256.0;
    

Reply
  • 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 / 256.0;
    

Children
No data