Question about adc and if statements

Thread Starter

hunterage2000

Joined May 2, 2010
487
Hi,

I have little experience with programming and wondered, say if you had a 10bit ADC and you wanted to output each decimal value onto an LCD so 0 to 1023.

Would you have to go through 1024 if or switch statements to act upon each value?
 

Papabravo

Joined Feb 24, 2006
21,159
In many programming languages there is an operator that gives the integer quotient of division and there is another operator that gives the remainder. If you divide a binary number between 0 and 1023 by 1000 there are only two possible quotients, namely 0 and 1, and a whole bunch of remainders in the range 0-999. What happens if you compute the quotient and remainder of that first remainder divided by 100? Get the idea?
 

ericgibbs

Joined Jan 29, 2010
18,766
hi 2000,
This Basic code fragment should be easy enough to convert to the language you are using.

[basic code]
Dim val(5) As Byte
Dim binval As Word
Dim bintemp As Word

start:
binval=1000
gosub bin2asc

end

bin2asc:
val(4) = binval / 10000
val(4) = val(4) Or 0x30

bintemp = binval Mod 10000
val(3) = bintemp / 1000
val(3) = val(3) Or 0x30

bintemp = binval Mod 1000
val(2) = bintemp / 100
val(2) = val(2) Or 0x30

bintemp = bintemp Mod 100
val(1) = bintemp / 10
val(1) = val(1) Or 0x30
val(0) = bintemp Mod 10
val(0) = val(0) Or 0x30

Return
[/basic code]
 

ErnieM

Joined Apr 24, 2011
8,377
Inside the stdlib.h library that should come with every C compiler there is a function "atoi" or ASCII to integer to convert a string to a number. A non standard extension to this library is "iota" for integer to ASCII conversion, or basically take an integer variable and convert it to a character string.

You may find this in your compiler library. If not you can add i as there are many implementation (ie, code) to be found on the interwebs.
 
Top