News:

Let's find out together what makes a PIC Tick!

Main Menu

Length of a string

Started by Teo, Feb 26, 2022, 09:53 PM

Previous topic - Next topic

Teo

Hi all,
I tried to write a program that would store in a variable 127 characters.
I can't store more than 32 characters....
I think I'm wrong somewhere
In the manual it says that the maximum length of a string is 255 characters


Dim Initial As Byte
Dim MyIndex As Byte
Dim Date_receptionate As String * 127

    Clear Date_receptionate
    MyIndex = 0
    Initial = 0
    RCREG1 = 0       
    While 1 = 1   
        HSerIn [Initial]                         
        If Initial = 62 Then Break       
        Date_receptionate[MyIndex] = Initial
        Inc MyIndex
        If MyIndex >= 126    Then
            MyIndex = 0
        EndIf       
    Wend

Any advice is much appreciated
Teo

shantanu@india

#1
What PIC are you using?
If it is a midrange 16F with banked memory structure then 127 bytes would inevitably spill over from one bank to another. There can be problems with 16F's...
18F's are better for handling big arrays.
Regards
Shantanu

Teo

Hi,
I use PIC18F46K22
Teo

trastikata

Quote from: Teo on Feb 26, 2022, 09:53 PMI can't store more than 32 characters....

Hello Teo,

How do you verify you can't store more than 32 characters?

Oskar-svr

#4
Hello friend TEO, I declare an array of variables in this way
and created an index with another variable to select which variable I want to save or read I hope it works for you
NOTE: remember that you must take into account that your RAM memory has a limit, since you are assigning greetings in RAM

dim X1 as byte
Dim MEMOw[80] as byte
example:
X1=1
MEMOw[X1]= any value in a byte

Teo

I need to receive a string of 127 characters, sort a few, and send them to the second UART.
I used PROTEUS for simulation and I saw that the received string has 32 characters.
Thanks in advance for your help,
Teo

top204

#6
A String variable can hold up to 255 characters, and I have just finished a program that received and stored ASCII values only in a String, so I know it works. Both the 18F and enhanced 14-bit core devices have linear RAM when used indirectly, which is how arrays and Strings operate. An array can hold as many elements as the RAM allows, up to 65535 elements.

When a String is sliced with the [index] mechanism, the compiler treats it as a Byte array while it is being loaded or read, and it all works well. But remember, if you are displaying or sending data from a String, a 0 will null it and cut it short where it lies within it. It is always a better idea to receive data into a Byte array, then it does not matter what value is received. The array can then be transferred to a String, or a String can be aliased to the Byte array itself.

My one piece of advice! Never trust a simulator 100%, always use a real device and run tests.

Teo

Hi Les,
Thank you very much
Teo

Teo

Hi Les,
You're right Simulator is defective
Thanks once again
Teo