BINTOASCII Implementation change...

PhilHornby

Senior Member
I just loaded a source file that I created under PE5 and found it will no longer compile. It does still compile and download using PE5.

Is this behaviour configurable in PE6?

This code:-

Rich (BB code):
bptr = ByteArray
     
      W0 = Time / 60                                        ;Convert Seconds to Minutes
      bintoascii W0,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc ; Convert Time to ascii
      bptr = ByteArray
      inc bptr                                              ;ignore the first digit
      ;
      ; Write Time to screen
      ;
      b0 = 16 : b1 = 1 : gosub LCD.SetCursor
     
      b0 = @bptrinc : gosub LCDSendData
      b0 = @bptrinc : gosub LCDSendData
      b0 = @bptrinc : gosub LCDSendData
      b0 = @bptrinc : gosub LCDSendData
gives this error (under PE 6.0.9.2)

bintoascii.png
 
Last edited:

hippy

Technical Support
Staff member
I cannot recall exactly why @bPtrInc etc were precluded from various commands but one can resolve the issue here by replacing BINTOASCII with a macro ...

Code:
#Macro BinToAsciiBPtrInc(wordValue)
  @bPtrInc = wordValue / 10000       + "0"
  @bPtrInc = wordValue / 1000  // 10 + "0"
  @bPtrInc = wordValue / 100   // 10 + "0"
  @bPtrInc = wordValue / 10    // 10 + "0"
  @bPtrInc = wordValue         // 10 + "0"
#EndMacro

w0 = 12345
bPtr = 10
BinToAsciiBPtrInc(w0)

SerTxd(b10,b11,b12,b13,b14)
In fact, it might be advantageous to move the 'bPtr=' assignment into the macro so you could use -

Code:
#Macro BinToAsciiBPtr(adr,wordValue)
  bPtr = adr
  @bPtrInc = wordValue / 10000       + "0"
  @bPtrInc = wordValue / 1000  // 10 + "0"
  @bPtrInc = wordValue / 100   // 10 + "0"
  @bPtrInc = wordValue / 10    // 10 + "0"
  @bPtrInc = wordValue         // 10 + "0"
#EndMacro

w0 = Time / 60
BinToAsciiBPtr( ByteArray, w0 )
If using an X2 rather than an M2 and 'Time' isn't going to change within the macro itself; you could use the following though it will use more memory, be a little slower to execute -

Code:
BinToAsciiBPtr( ByteArray, Time / 60 )
 
Last edited:

hippy

Technical Support
Staff member
Looking at what your program does, you could optimise that considerably. Existing code 101 bytes for 08M2 using PE5, 63 bytes on PE6 with ...

Code:
#Macro Send_4_Digits_To_Lcd(x,y,wordValue)
  b0 = x : b1 = y        : Gosub LCD.SetCursor
  b0 = wordValue / 1000  : Gosub LCDSendDigit
  b0 = wordValue / 100   : Gosub LCDSendDigit
  b0 = wordValue / 10    : Gosub LCDSendDigit
  b0 = wordValue         : Gosub LCDSendDigit
#EndMacro

w2 = Time / 60
Send_4_Digits_To_Lcd( 16,1 , w2 )

LCDSendDigit:
  b0 = b0 // 10 + "0"
LCDSendData:
 
Last edited:

PhilHornby

Senior Member
I'm aware that I could optimise this (and other programs I have, that use the same technique), but I wanted to use my previously tested and working code *there and then*. (It's part of a temperature logger, and my mission at that moment was to log temperatures, not write code!)

Using a macro, in the way you suggest sounds like a sensible way out of my dilemma. I knew that I couldn't 'overwrite' BintoAscii with a macro of the same name (sadly!) - but it's fairly trivial to call a differently named one instead.

Needless to say, I think that future versions of Picaxe Editor should be backwards compatible, unless there is an overwhelming reason why not.

Thanks for your help.
 

hippy

Technical Support
Staff member
Using a macro, in the way you suggest sounds like a sensible way out of my dilemma. I knew that I couldn't 'overwrite' BintoAscii with a macro of the same name (sadly!)
Seems that one can with just a minor bit of editing ...

Code:
Macro BinToAscii(wVar,n1,n2,n3,n4,n5)
  n1 = wVar / 10000 // 10 + "0"
  n2 = wVar / 1000  // 10 + "0"
  n3 = wVar / 100   // 10 + "0"
  n4 = wVar / 10    // 10 + "0"
  n5 = wVar         // 10 + "0"
#EndMacro

bPtr = 10
w0 = 12345
BinToAscii(w0,@bPtrInc,@bPtrInc,@bPtrInc,@bPtrInc,@bPtrInc)
SerTxd(b10,b11,b12,b13,b14)
 

Buzby

Senior Member
I too am surprised that you can make a macro with the same name as an existing command.

That opens up all kinds of opportunities for fun !.

EDIT : I'll try when I get home.
 

hippy

Technical Support
Staff member
I would have put money on having tried and failed to do that in the past!
I was a bit surprised when I tested it but it makes sense. Because it's a macro the pre-processor is stripping "BinToAscii" out entirely so that never gets through to the compiler which would be what would complain about syntax issues and the like.

What I suspect will make it not work and give errors is where an actual BINTOASCII is used additional to the macro or within the macro. And maybe where one needs the flexibility of byte and word BINTOASCII commands.
 

Buzby

Senior Member
Yep, it works, and as hippy says, you can't use both at the same time !.

You can even make a macro called 'Symbol' .
 
Top