How can I simulate -X1 DIG command on older chips

johnmobley

New Member
Ok here it goes. I have been working on a picaxe project and I have found that using a 28X1 I can do exactly what I want (the DIG command is only valid with "X1" chips). However a 28X1 is actually a lot of overkill for what I am wanting to do. Below is the code that I can use with the 28X1:

Code:
Let w0 = 3293
Let w1 = w0 DIG 0
Let w2 = w0 DIG 1
Let w3 = w0 DIG 2
Let w4 = w0 DIG 3
Serout 7,T2400,(254,1,254,192,#w4, ".", #w3, #w2, #w1)
The value of w0 would actually come from a count or pulsin command and so the first line of the code above would be different, it is just for this example. When run it would break down the number stored in w0 into its individual numbers and then show 3.293 on the second line of the LCD Display. This is exactly the result that I want.

My question is, how can i do the same thing with a smaller picaxe chip that is not a "X1" chip? I know I could just use the "X1" chip but I really dont want to if I dont have to.
 

moxhamj

New Member
Can the bintoascii command do this? Just looking at it, I think it should result in fairly short code - maybe no longer than what you have.
 

westaust55

Moderator
If all you want to do is display a value with no further maths on the individual digits then I agree with Dr-Acula. Use the BINTOASC command.

Then the individual digits are already ASCII encoded, so there will be no need to place the # symbol in front of the variable in the SEROUT command.
 

johnmobley

New Member
That is what I tried to use first. My original code was:

Code:
Let w0 = 3293
bintoascii w0,w1,w2,w3,w4
serout 7,T2400,(254,1,254,192,w4,".",w3,w2,w1)
Upon trying this code I would recieve a syntax error at the bintoascii line. I then tried the bcdtoascii command, but it obviously made some unexceted conversions because it displays the value 61.616048 on the LCD. If I understand correctly if I got the bintoascii command to work it would do something simular because it is working with binary numbers and then converting them to their corresponding ascii characters, not the actual number shown in the w0 variable. Or am I not writing the code correctly?
 
Last edited:

boriz

Senior Member
Maybe it doesn’t like Word variables for the digits, or maybe it needs 5 digit variables.
 

johnmobley

New Member
Thank you so much for the help. I was on the right track but looking for the wrong train. Thanks boriz, I did not think about spliting the word variable into separate byte variables but that did indeed do the trick. I am up and running (programming) again.
 

westaust55

Moderator
Bintoasc

Ah, was about to give the same answer as Boriz then realised he had another post.

A good example of why posting the actual problematic code at the start can be useful.

Another case for an edit to Manual 2 clearly indicating that the resultant variables should be byte variables even when the input variable is a word.
 
Top