TomMystery
New Member
I need a program to take an ADC value and split each of the numbers into seperate variables. Since I do not know of a specific command that will allow me to do that I wrote the following program. Unfortunately it is too long by 3 bytes. Any ideas as to what I could do to reduce the size of the program? Or whether there is another way to do it?
readchip:
readadc 1,b0
first:
if b0 >= 200 then th
th:
let b1 = 2
let b0 = b0 - 200
goto second
if b0 >= 100 then oh
oh:
let b1 = 1
let b0 = b0 - 100
goto second
if b0 > 100 then nh
nh:
let b1 = 0
second:
if b0 >= 90 then nit
nit:
let b2 = 9
let b0 = b0 - 90
goto third
if b0 >= 80 then eit
eit:
let b2 = 8
let b0 = b0 - 80
goto third
if b0 >= 70 then svt
svt:
let b2 = 7
let b0 = b0 - 70
goto third
if b0 >= 60 then sit
sit:
let b2 = 6
let b0 = b0 - 60
goto third
if b0 >= 50 then fit
fit:
let b2 = 5
let b0 = b0 - 50
goto third
if b0 >= 40 then fot
fot:
let b2 = 4
let b0 = b0 - 40
goto third
if b0 >= 30 then tht
tht:
let b2 = 3
let b0 = b0 - 30
goto third
if b0 >= 20 then twt
twt:
let b2 = 2
let b0 = b0 - 20
goto third
if b0 >= 10 then tet
tet:
let b2 = 1
let b0 = b0 - 10
goto third
if b0 > 10 then zet
zet:
let b2 = 0
third:
if b0 = 9 then ni
ni:
let b3 = 9
goto sendvalue
if b0 = 8 then ei
ei:
let b3 = 8
goto sendvalue
if b0 = 7 then se
se:
let b3 = 7
goto sendvalue
if b0 = 6 then si
si:
let b3 = 6
goto sendvalue
if b0 = 5 then fi
fi:
let b3 = 5
goto sendvalue
if b0 = 4 then fo
fo:
let b3 = 4
goto sendvalue
if b0 = 3 then thr
thr:
let b3 = 3
goto sendvalue
if b0 = 2 then two
two:
let b3 = 2
goto sendvalue
if b0 = 1 then one
one:
let b3 = 1
goto sendvalue
if b0 = 0 then ze
ze:
let b3 = 0
sendvalue:
serout 0,N2400, (b1)
serout 2,N2400, (b2)
serout 4,N2400, (b3)
goto readchip
readchip:
readadc 1,b0
first:
if b0 >= 200 then th
th:
let b1 = 2
let b0 = b0 - 200
goto second
if b0 >= 100 then oh
oh:
let b1 = 1
let b0 = b0 - 100
goto second
if b0 > 100 then nh
nh:
let b1 = 0
second:
if b0 >= 90 then nit
nit:
let b2 = 9
let b0 = b0 - 90
goto third
if b0 >= 80 then eit
eit:
let b2 = 8
let b0 = b0 - 80
goto third
if b0 >= 70 then svt
svt:
let b2 = 7
let b0 = b0 - 70
goto third
if b0 >= 60 then sit
sit:
let b2 = 6
let b0 = b0 - 60
goto third
if b0 >= 50 then fit
fit:
let b2 = 5
let b0 = b0 - 50
goto third
if b0 >= 40 then fot
fot:
let b2 = 4
let b0 = b0 - 40
goto third
if b0 >= 30 then tht
tht:
let b2 = 3
let b0 = b0 - 30
goto third
if b0 >= 20 then twt
twt:
let b2 = 2
let b0 = b0 - 20
goto third
if b0 >= 10 then tet
tet:
let b2 = 1
let b0 = b0 - 10
goto third
if b0 > 10 then zet
zet:
let b2 = 0
third:
if b0 = 9 then ni
ni:
let b3 = 9
goto sendvalue
if b0 = 8 then ei
ei:
let b3 = 8
goto sendvalue
if b0 = 7 then se
se:
let b3 = 7
goto sendvalue
if b0 = 6 then si
si:
let b3 = 6
goto sendvalue
if b0 = 5 then fi
fi:
let b3 = 5
goto sendvalue
if b0 = 4 then fo
fo:
let b3 = 4
goto sendvalue
if b0 = 3 then thr
thr:
let b3 = 3
goto sendvalue
if b0 = 2 then two
two:
let b3 = 2
goto sendvalue
if b0 = 1 then one
one:
let b3 = 1
goto sendvalue
if b0 = 0 then ze
ze:
let b3 = 0
sendvalue:
serout 0,N2400, (b1)
serout 2,N2400, (b2)
serout 4,N2400, (b3)
goto readchip