Proton BASIC Compiler - Print Table Strings

  • PicŪ Basic

  • Print Table Strings

    Theses libraries are used to print strings written in tables and help avoid some typos.
    I extracted some code from the manual. Please see the Ldata/Lread, Cdata/Cread in the PDS manual.

    I propose 2 examples:
    1- Print the strings using a number (number of strings in the list).
    2- Print the strings using the name of the Label.

    Number of the string:
    The command is: PrintStrg(4,1,1)
    Print the string number 4 to line 1, position 1 of the LCD.
    The number 4 could be changed to a variable: PrintStrg(MenuNumber,1,1)
    The 'MenuNumber' variable could be used in a loop to scan a menu, incrementing the value.
    This solution uses a table of string addresses and so occupies more memory.
    For example:
    StrgsTable: LData As Word Text0,Text1,Text2,Text3,Text4,Text5,Text6
    Text0: LData "HELLO",0
    Text1: LData "WORLD",0
    Text2: LData "PrintStrg is a",0
    Text3: LData "command to read",0
    Text4: LData "Ldata tables",0
    Text5: LData "Thank You",0
    Text6: LData "Error String",0
    Name of the Label of the string:
    The command is: PrintLStrg(Text0,1,1)
    Print the string whose label is 'Text0' to line 1, position 1 of the LCD.
    This solution needs less memory but is restricted to printing a particular string. (NO address table)
    Text0: LData "HELLO",0
    Text1: LData "WORLD",0
    Text2: LData "PrintStrg is a",0
    Text3: LData "command to read",0
    Text4: LData "Ldata tables",0
    Text5: LData "Thank You",0
    With the preprocessor it is possible to compile different languages,
    $ifdef _English_
    Text0: LData "HELLO" ,0
    Text1: LData "WORLD",0
    Text2: LData "PrintStrg is a",0
    Text3: LData "command to read",0
    Text4: LData "Ldata tables",0
    Text5: LData "Thank You" ,0
    Text6: LData "Error String",0
    $ifdef _Spanish_
    Text0: LData "HOLA",0
    Text1: LData "MUNDO" ,0
    Text2: LData "PrintStrg es un",0
    Text3: LData "comando para ver" ,0
    Text4: LData "las tablas Ldata" ,0
    Text5: LData "Gracias",0
    Text6: LData "Texto erroneo",0
    $ifdef _French_
    Text0: LData "SALUT",0
    Text1: LData "LE MONDE" ,0
    Text2: LData "PrintStrg es une" ,0
    Text3: LData "macro pour lire",0
    Text4: LData "les tables Ldata",0
    Text5: LData "Merci",0
    Text6: LData "Erreur Texte",0
    How to build the library:
    1- How to define a local variable.
    I usually use the preprocessor to build blocks of local variables. Repeat these blocks until the required number of variables is reached. By writing the necessary blocks in different libraries, some local variables are achieved without complaint from the compiler.
    $ifndef _LVBS_Block1_
        $define _LVBS_Block1_
        Dim LVSByte1 As Byte System     ' Local Variable System Byte1
        Dim LVSByte2 As Byte System     ' Local Variable System Byte2
        Dim LVSByte3 As Byte System     ' Local Variable System Byte3
        Dim LVSByte4 As Byte System     ' Local Variable System Byte4
    If you need more variables to build another block.
    $ifndef _LVBS_Block2_
        $define _LVBS_Block2_
        Dim LVSByte5 As Byte System     ' Local Variable System Byte5
        Dim LVSByte6 As Byte System     ' Local Variable System Byte6
        Dim LVSByte7 As Byte System     ' Local Variable System Byte7
        Dim LVSByte8 As Byte System     ' Local Variable System Byte8
    Now you must assign the different variables.
        Dim xCharPos  As LVSByte1       ' As Local Variable
        Dim xNbString As LVSByte2       ' As Local Variable
        Dim xDataByte As LVSByte3       ' As Local Variable
        Dim xLine     As LVSByte4       ' As Local Variable
        Dim xAddress  As LVSWord1       ' As Local Variable
    2- How to build the macro.
    You can use the library manager and modify the macro.
    Usually I write the macro manually, so I get better control of the parameters with the preprocessor.

    With the macro I can control these parameters.
    Too few parameters
    LCD Characters Length
    Last String written in the LData/CData table
    Line number
    Character position
    Number of string: Number 8/Byte or Label
    Number of the line: Number 8
    Number of character position: Number 8

    3- The code.
    The original code comes from the PDS manual.
    Inside the subroutine the control of the last string is needed, because the PIC will crash if the string number is not written in the table. Try the demo.

    4- Different cores.
    There are different codes for PIC16 and PIC18. Because LData/LRead is used for PIC16 and CData/Cread is used for PIC18.

    5- PIC18 and Label.
    There is a very efficient code in the manual to print Strings using a Label and the Cstr modifier.
    Print At 2,1, CStr Text0
    The trick of the macro is to paste this code and use the macro to test the parameters only.

    6- Examples
    There are several demo.bas for each case. You can test using the ISIS included with the PDS compiler.
    Enjoy theses new libraries.

    Update: 22/01/2016 version 2.0
    Added a new feature for PrintStrg(x,y,z) command:
    Normally the PrintStrg(NbString,x,y) command write a String numberX to the LCD in Line x, character position y.
    Now two commands can be chained to print 2 strings in a single line.
    PrintStrg(5,1,1) : PrintStrg(7,0,0)
    The second command prints a text (String number 7) on the same line attached to the latter String number 5.

    PrintStrg(5,1,1) : PrintStrg(7,0,1)
    The second command prints a text (String number 7) on the same line with a space character to the latter String number 5.

    New command: Print Piece Of String
    PrintPOStrg(Number String, First Char, Last Char, Number of Spaces)
    PrintPOStrg(Number String, First Char, Last Char)
    This command enables to Print a piece of a string, saved in a CData table.
    The number of spaces are printed before the string and it is optional.
    The position of the Cursor must be written first.

    New command: Print a String from a determined Lable.
    PrintLStrg(Label name, Line Numer, Character Position)

    Update: 29/01/2016 version 2.1
    Changing the language on the fly.
    Thanks to Tim's suggestion, I worked more on reading tables. If the tables are placed in a particular position a simple formula could be used to find the desired language. The new command to change the language on the fly is ChooseLanguage(English) (or Spanish or French, etc ...)
    The Print command PrintStrg(x, y, z) practically not changed, only adding a Word variable.

    The tables are placed in this way.
    EnglishTable: CData As Word Text0A,Text1A,Text2A,Text3A,Text4A,Text5A,Text6A
    SpanishTable: CData As Word Text0B,Text1B,Text2B,Text3B,Text4B,Text5B,Text6B
    FrenchTable:  CData As Word Text0C,Text1C,Text2C,Text3C,Text4C,Text5C,Text6C
    Text0A: CData "HELLO",0
    Text1A: CData "WORLD",0
    Text2A: CData "PrintStrg is a",0
    Text3A: CData "command to read",0
    Text4A: CData "Cdata tables",0
    Text5A: CData "Thank You",0
    Text6A: CData "Error String",0
    Text0B: CData "HOLA",0
    Text1B: CData "MUNDO",0
    Text2B: CData "PrintStrg es un",0
    Text3B: CData "comando para ver",0
    Text4B: CData "las tablas Cdata",0
    Text5B: CData "Gracias",0
    Text6B: CData "Texto erroneo",0
    Text0C: CData  "SALUT" ,0
    Text1C: CData "LE MONDE",0
    Text2C: CData "PrintStrg es une",0
    Text3C: CData "macro pour lire",0
    Text4C: CData "les tables Cdata",0
    Text5C: CData "Merci",0
    Text6C: CData "Erreur Texte",0
    Of course this method runs better with the PrintStrg (x, y, z) or HRSStrg(x, y, z) commands.
    These commands are compatible with languages initialized at compile time or changed on the fly.
    Now the commands can read a large amount of CData strings. I have also tried to improve the code.
    I added similar commands to read the tables and send strings to the terminal by the UART1 channel. ""
    Alberto Freixanet
    (Barcelona Spain)
  • Recent Activity


    Valid time in NMEA sentance

    Thread Starter: SimonJA

    Is there any way to know that a GPS nmea sentence has the correct time? I use a module to keep a pic rtc accurate but have noticed that when...

    joesaliba Today, 16:30 Go to last post

    I'm over the moon with joy. :-)

    Thread Starter: Les

    I just had to show you this, because I am over the moon with it. LOL I've just about finished procedures on the Proton 8-bit compiler so I am busy...

    towlerg Today, 16:13 Go to last post
    John Drew-26

    GPS speed logger for RC planes.

    Thread Starter: david

    Hi All, This is a simple project to allow the logging of RC plane speeds to help determine battery, motor and prop variables. The code is crude and...

    John Drew Today, 01:31 Go to last post