Serial communications picaxe to picaxe IDE

depeet

New Member
I want to read the contents of b0 till b5, or w0 till w3, and send them to the Picaxe IDE. (terminal window) I thought about this way.

Code:
Sertxd ("word 1", b1, b0, CR, LF)
Sertxd ("word 2", b3, b2, CR, LF)
Sertxd ("word 3", b5, b4, CR, LF)
Is there a more efficient way with, for example, @bptr?

Code:
For bptr = 0 to 5
sertxd ("word 1", @bptr, @bptrinc, CR, LF)
next bptr
If this would work, then b0 would be sent before b1 while it should be just the other way round.
 

Aries

New Member
If you are intending to pass the values as decimal numbers, then you need to precede the variables with # (e.g. #b0), otherwise they will be interpreted either as characters (when they print as such) or non-printing characters (when they appear as decimal values in square brackets).

The code you suggest will not work. You are incrementing bptr inside the loop as well as it being the loop counter, so you will not get what you expect anyway. If you try the code in the simulator, you can see what would happen. You are also repeating "word 1" at the start of each line, so you won't necessarily know what you are getting.

Are you really concerned as to whether the values appear the "right" way round? If not, then you can do something like this:
Code:
bptr = 0
do
    sertxd("b",#bptr,"=",#@bptrinc," b",#bptr,"=",#@bptrinc,CR,LF)
loop until bptr > 5
To achieve what you originally asked for - it depends what you mean by efficient. This code works, and can be expanded to print any set of pairs of b-variables:
Code:
bptr = 1
do
    bptr = bptr + 1 / 2
    sertxd("word ",#bptr)
    bptr = bptr * 2 - 1
    sertxd(" ",#@bptrdec," ",#@bptr,CR,LF)
    bptr = bptr + 3
loop until bptr > 5
 

hippy

Technical Support
Staff member
Similar to Aries' last example, I would probably have gone for -
Code:
For bPtr = 0 To 2
  SerTxd( "w", #bptr, TAB )
  bPtr = bPtr + bPtr | 1
  SerTxd( "b", #bptr, "=", #@bPtrDec, TAB, "b", #bptr, "=", #@bPtr, CR, LF )
  bPtr = bPtr / 2
Next
Initialised with -
Code:
For bPtr = 0 To 5
  @bPtr = bPtr
Next
That outputs -
Code:
w0    b1=1  b0=0
w1    b3=3  b2=2
w2    b5=5  b4=4
But I'm not sure it's any more 'efficient' than what you originally had with three explicit SERTXD commands.
 
Top