News:

;) This forum is the property of Proton software developers

Main Menu

Equivalent to CHR()

Started by kcsl, Aug 30, 2024, 07:44 AM

Previous topic - Next topic

kcsl

I'm sure I've done this before but can't for the life of me remember how.
I want to add a CR and LF to the end of a string.

I thought I could do something like
       string = "text" + chr(10) + chr(13)
but chr() isn't supported.

Can somebody please tell me the syntax to do this?

Interesting when searching the help manual, I see that CHR$ is in the protected compiler word list but there's no other reference to it.

Kind regards,
Joe

There's no room for optimism in software or hardware engineering.

RGV250

Hi,
I am assuming you want to send it to a serial port, this is all I do.
HSerOut ["Temperature ", Dec2 Temperature,10,13]         

Bob

top204

#2
You can use the constant values in a String and they will be added as ASCII values, or if it is a quoted character string only, use the "\n\r", where "\n" is new line and "\r" is carriage return.

See page 38 in the Positron8 PDF manual, in the "Quoted String of Characters" paragraph:

Dim MyString As String * 30
   
MyString = "Hello World" + 10 + 13


or
 
MyString = "Hello Again\n\r"

If it is only a quoted character string, use the "\n\r", because this will create smaller assembler code, because it will all be placed in the assembler flash memory table for the contents of it:

;---------------------------------------------
; USER. STRING VARIABLE PRE-LOADS
_strlb__1
    db 72,101,108,108,111,32
    db 65,103,97,105,110,10
    db 13,0


F1_000056 equ $ ; in [TEST_18F25K20.BAS] MyString = "HELLO AGAIN\N\R"
    lfsr 0,MyString
    movlw ((_strlb__1 >> 8 ) & 0xFF)
    movwf TBLPTRLH,0
    movlw (_strlb__1 & 0xFF)
    movwf TBLPTRL,0
    rcall __load_flashstring_to_RAM_
    clrf INDF0,0


Whereas adding the values will create a bit extra code memory usage in order to add the constant values to the quoted string held in flash memory:

;---------------------------------------------
; USER. STRING VARIABLE PRE-LOADS

_strlb__1
    db 72,101,108,108,111,32
    db 87,111,114,108,100,0


F1_000055 equ $ ; in [TEST_18F25K20.BAS] MyString = "HELLO WORLD" + 10 + 13
    lfsr 0,MyString
    movlw ((_strlb__1 >> 8 ) & 0xFF)
    movwf TBLPTRLH,0
    movlw (_strlb__1 & 0xFF)
    movwf TBLPTRL,0
    rcall __load_flashstring_to_RAM_
    movlw 10
    movwf POSTINC0,0
    movlw 13
    movwf POSTINC0,0
    clrf INDF0,0


Chr$ was something I was probably going to add to the compiler, but I changed it to Str$ and forgot to remove it from the manual's keywords section.

kcsl

Thanks Les,
 
Interesting about the quoted characters resulting in smaller code.
Anyway, that clears things up for me, thanks.

Kind regards,
Joe
There's no room for optimism in software or hardware engineering.