RE: Manipulation of 12 bit ADC data using C programming
Read them out in the order specified in the data sheet.
Shift the high-order byte left as many steps as is required, based on
how many bits the data sheet says in the low-order byte.
Check align of the bits in the low-order byte and possibly shift to
correct position before oring together the high and low values. Just
make sure that your intermediate results fits.
By the way. Stay away from magical numbers. You are adding 48 to
convert from binary to ASCII. Instead add with '0' to make it more
You would get a lot less code if you use a loop for converting the
ADC value to decimal. Something like.
Make sure that your function names says what they do. A function
"one()" doesn't say anything about what it do. A function
"process_ones_digit()" gives more info.
I don't see your variable declarations, but your function
bit_resolution() plays with floating point. Try to avoid if possible.
Computing 3/4096 do require floating point.
Computing (value*3)/4096 will not require floating point, unless
the end result is expected to have fractions. If the end result is
expected to have one decimal, you can do (10*value*3)/4096 and
remember that when you convert from binary to decimal, there should
be a decimal separator before the last emitted digit. Once more -
make sure that the intermediate product must not suffer from numeric