Use variable to set qualifier

KeithRB

Senior Member
I am reprogramming the 18M2 in the OLED. I am trying to display GPS stuff coming in over a bluetooth modem. I would like to select various NMEA sentences for display and create a subroutine to do that. Is there a way to use variables to set the serin qualifier?
 

geoff07

Senior Member
I haven't tried it, but I would expect any byte variable to do the job. Just assign the value you want to the variable and use the name of the variable in the command.
 

hippy

Technical Support
Staff member
Yes -

b1 = "A"
b2 = "B"
b3 = "C"
Serin PIN, BAUD, ( b1, b2, b3 ), ....

Is just the same as -

Serin PIN, BAUD, ( "ABC" ), ....
 

geoff07

Senior Member
It is true that Picaxe does not recognise string variables, or have string functions. And yet .. in practice, bytes containing ascii character codes and stored contiguously are a string in some limited ways.
 

hippy

Technical Support
Staff member
Strings can be used in some places within PICAXE commands. They aren't strings as such but separate character bytes -

Serin PIN, BAUD, ( "ABC" ), ....

Is really a shortform for -

Serin PIN, BAUD, ( "A", "B", "C" ), ....
 

KeithRB

Senior Member
Which is why I was confused...

I am pretty language agnostic, (Well, except for BF), but I really wish subroutines had their own variable space.
 

geoff07

Senior Member
I really wish subroutines had their own variable space
A problem with implementing block structured languages with local variables is all the context saving and restoring.

However, the recent presence of push and pop lead one to wonder if functions are around the corner ..
 

hippy

Technical Support
Staff member
Thanks for that, but I have to use the 18M2 since that is what you guys put on the OLED. 8^)
On non-X2's it is possible to use the RAM and 'bptr' variable to implement a LIFO stack and use macros to create PUSH and POP equivalents ...

Code:
#Picaxe 18m2
#Terminal 4800

#Macro PUSH(bytevar)
  dec bptr
  @bptr = bytevar
#EndMacro

#Macro POP(bytevar)
  bytevar = @bptrInc
#EndMacro

Pause 2000
For b0 = 1 To 10
  SerTxd( #b0, " " )
  Gosub MySub
  SerTxd( #b0, CR, LF )
Next
End

MySub:
  PUSH(b0)
  b0 = 99
  SerTxd( #b0, " " )
  POP(b0)
  Return
 

KeithRB

Senior Member
#Macro?

What is that? I guess it is time to download a new picaxe_manual2!

But great idea, hippy! I will have to see if I can spare any RAM from my serial buffer!

ETA:
It might be a good idea to put a revision number in the manual file name.
 
Top