Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to convert the values ????from AD0 to 255 of the microcontroller into voltages
How to convert the values ????from AD0 to 255 of the microcontroller into voltages

If the reference voltage of the AD chip you use is 5V, that means dividing the 5V into 256 parts, and the size of each part is (5/256.)V. Note that floating point is required here. For calculation, add a decimal point after 256 to get the decimal, otherwise the calculation will always be 0. In this way, there are so many copies. If you read AD, you get 99, which means you have read 99 copies. Then you can get the voltage value by multiplying it by the resolution (5/256.).

That is: voltage = (float)( 99*(5/256.));

voltage should be a foam type variable, because after the previous operation, voltage is The actual voltage value comes out. Assume that the calculated value is 2.786543. When it is displayed, you will always get 0 by directly /100. So it needs to be converted to an integer first.

Suppose we need to save 3 decimal points, so we first multiply the result by 1000, and assign the result to an integer variable tmp = 2786

Then separate it, tmp/1000; tmp%1000/100... (I won't write it, you know), convert it into ASCII code, and finally pay attention to displaying a decimal point after the first data and it will be OK.