Hi all
I am working on the digits now, and I think I have almost got it sorted (or not!)
I just can't see where I am going wrong and I'm sure it's the way I'm working with the array.
To somplify things I have given the variable a set number, the number 123 as in my examples above.
here's the code so far
Code:
Start:
Codex VAR BYTE
Temp VAR BYTE [3]
TempTot var byte
Codex = 123
Tempx var byte
'Find character for decimal 100 column
Tempx = Codex/100 'divide Codex by 100 'cos its the digit in 100's column
Temp(0) = Tempx + 48 'add 48 to get ascii value
lcdout "first " ,temp(0)
HSEROUT ["1st digit ", Temp(0),$0d,$0a]
pause 1000
'Find character for decimal 10 column
Tempx = Codex/10 'since Codex = 123 after dividing Temp = 12
Temp(1) = Tempx//10 'Remainder is required so with Codex = 123 the number in Temp = 2
Temp(1) = Tempx + 48 'add 48 to get ascii value
lcdout "second ",temp(1)
HSEROUT ["2nd digit ", Temp(1),$0d,$0a]
pause 1000
'Find character for decimal 1 column
Tempx = Codex//10 'Get Remainder so…with Codex = 123 then Temp = 3
Temp(2) = Tempx + 48 'add 48 to get ascii value
lcdout "third ",temp(2)
HSEROUT ["3rd digit ", Temp(2),$0d,$0a]
pause 1000
TempTot = Temp(0)+temp(1)+Temp(2)
hserout ["here's the binary total ",dec temptot,$0d,$0a]
hserout ["here's the binary total ",bin temp,$0d,$0a]
goto start
Observations:
The first and third digits are correct , the second is a problem (and I think it's the wrong number since it shows up as a ">" character ) so this obviously messes up the total after addition which ends up as 160 as opposed to 123 :-(
Here is what I see in the MCS serial tool window
Code:
1st digit 1
2nd digit <
3rd digit 3
here's the binary total 160
here's the binary total 110001
Any help would be appreciated
Dennis
Bookmarks