Hi all..
currently im using C8051F226 using silab in C language.. and my display is using a display module uOLED-96-G1..
i've set up the ADC and it work fine.. and now when i input a voltage of 0 to 3v, i'll get the int ADCvalue as 0 to 255... and im able to display the number on the uOLED. ADCvalue = ADC0H..
What i want to do now is to convert the ADC value back to the analog value...e.g.
if my int ADCvalue is 255.. i want to get 3.0
if my int ADCvalue is 127 or 128.. i want to get 1.5
if my int ADVvalue is 0.. i want to get 0.0... etc..
i've already printed the decimal point('.') on my display.. so now i need to get 2 seperate interger
when my ADCvalue is 255... i want '3' & '0'
when my ADCvalue is 127 or 128... i want '1' & '5' etc...
the problem is that my display wont be able to do printf function.. meaning i cant use the %f, %d, etc...
can any1 please help me with some calculation coding?? does it got to do with the bits resolution?
Hi,
Try something like:
Variable = (ADCvalue * 30) >> 8
d1 = Variable div 10
d2 = Variable mod 10
Then d1 stores the tens value as integer, d2 stores units value as integer.
Now just print d1 and d2.
Hope it helped.
Tahmid.
Hi vailant,
">>8" means bitshift right eight times, in other words, divide by 255.
So 255*30=7650
7650>>8 = 30
30/10 = 3
30%10 = 0
So, d1 = 3, d2 = 0
Print this on LCD, with the "." printed between d1 and d2.
Another example, if result = 128,
128*30=3840
3840>>8=15
15/10= 1
15%10 = 5
so, d1 = 1, d2 = 5
Print this with "." in between, so 1.5
Hope it helped.
Tahmid.
Hi Tahmid,
Yes! it works! thank you so much.. i only hope that i could check your reply earlier. because i actually try to figure it out myself and i came out with a longer n stupid coding..