Today 07:21
Forum: Tips 'n Tricks
Starter: canilica
Views: 0
Replies: 0
Yesterday 14:59
Forum: Projects discussion
Starter: Pic
Views: 0
Replies: 2
+ Reply to Thread
Results 1 to 9 of 9

Thread: Replace Label with String39 days old

  1. #1
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    765
    Thumbs Up
    Received: 16
    Given: 11
    Total Downloaded
    382.78 MB

    1 Not allowed!

    Default Replace Label with String

    I would like read font data in a procedure using Cread something like this:

    Code:
    dataOut = CRead8 myFontFile[index]
    Where myFontFile is a string in order that I can use one procedure to print different fonts stored in separate font tables, BUT the compiler will only accept a label.

    For example my procedure would look like this:

    Code:
    Proc printChar(textFont As String * 10, Char As Byte, Page As Byte, Column As Byte)
    ...
    dataout = Cread8 textFont[index]
    ...
    and I would use it like this:

    Code:
    printChar("Arial_15x16", "A", 0, 0)
    But I can't do that and anything else I can think of is very messy, Anyone have any ideas?

  2. #2
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    765
    Thumbs Up
    Received: 16
    Given: 11
    Total Downloaded
    382.78 MB

    0 Not allowed!

    Default Re: Replace Label with String

    I just found Addressof in the manual and I think that will allow me send the location of the font data in memory to the procedure...

  3. #3
    Senior Member AlbertoFS's Avatar
    Join Date
    Apr 2005
    Posts
    594
    Thumbs Up
    Received: 81
    Given: 2
    Total Downloaded
    1.94 GB

    0 Not allowed!

    Default Re: Replace Label with String

    I have discussed this topic several times in the forum. I had written a library to read the Strings in the Cdata tables. I have not studied the PIC24 and I did not write the procedures. But it can help you with some macros with the pre-processor that could transform into a procedure for the PIC24.

    1-You have to get the address of the Cadata line in the ROM of the String.
    2- You have to increase the pointer of the ROM to extract the data from the String.

    It is an example for PIC18F25K20.

    To point the ROM (macro)
    Code:
        $define PointToCdataStrg(pString) '
        $if _code > 65536                 '
        Asm                               '
        Movlw Low (pString)               '
        Movwf TBLPTRL                     '
        Movlw High (pString)              '
        Movwf TBLPTRH                     '
        Movlw upper (pString)             '
        Movwf TBLPTRU                     '
        EndAsm                            '
        $else                             '
        Asm                               '
        Movlw Low (pString)               '
        Movwf TBLPTRL                     '
        Movlw High (pString)              '
        Movwf TBLPTRH                     '
        Clrf  TBLPTRU                     '
        EndAsm                            '
        $endif
    To increment the ROM address:
    Code:
        $define IncTBLPTR() '
        Asm                 '
        Incf TBLPTRL,F,1    '
        Movlw 0             '
        Addwfc TBLPTRH,F,1  '
        Addwfc TBLPTRU,F,1  '
        EndAsm
    To Print:
    Code:
        PointToCdataStrg(StringArray1)
        Set EECON1Bits_EEPGD        ' Access flash memory       
        Do
            Tblrd*+                     ' Read one memory position.
            If TABLAT = 0 Then Break
            Print TABLAT
            IncTBLPTR()                 ' Increment the ROM address
        Loop 
        
        StringArray1: CData "My Font String",0
    Please try to transform these codes to procedures.
    Maybe I did not understand the question well?
    It is everything that I can propose. I hope it could be useful.
    Regards
    Last edited by AlbertoFS; 15th January 2018 at 15:59.
    [U]73's de Alberto ea3agv[/U]

  4. #4
    Developer Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,309
    Thumbs Up
    Received: 266
    Given: 110
    Total Downloaded
    1.50 GB

    0 Not allowed!

    Default Re: Replace Label with String

    A String is held in RAM, however, Cread , Cread8, Cread16, and Cread32 are for reading from Flash (code) memory, which is were a font table will sit using either Cdata or, better still, Dim as Code.

    What is required is reading from the address of the flash memory data that may hold a font, and that's where the Cptr8, Cptr16 and CPtr32 commands come in, as they are used for reading pointers. i.e. The silly "C" language name for Addresses. Also required is the ByRef directive in the procedure's parameter, as this informs the procedure to use the address of a variable or data table etc...

    The demo below shows the mechanism for reading a pointer. i.e. Address

    Code:
    ' A simple demo to show reading from a flash memory address
    '
        Device = 24FJ64GA002 
        Declare Xtal= 32
    
        Declare Hserial_Baud = 9600         ' USART1 baud rate
        Declare HRSOut1_Pin = PORTB.14      ' Select the pin for TX with USART1
    
    
        CLKDIV = 0                              ' \
        Write_OSCCONH($10)                      ' / Enable the PLL to operate the device at 32MHz
        RPOR7 = 3                               ' Make PPS Pin RP14 U1TX
    '
    ' Create data in flash memory
    '    
        Dim MyFlashData As Code = 0,1,2,3,4,5,6,7,8,9,_
                                  10,11,12,13,14,15,16,17,18,19,_
                                  20,21,22,23,24,25,26,27,28,29,_
                                  255
                             
    '----------------------------------------------------------------------
    ' Read Flash Memory data
    ' Input     : pFlashAddress holds the address of the data in flash memory
    ' Output    : None
    ' Notes     : Serially Transmits the data read from flash
    '
    Proc ReadFlash(ByRef pFlashAddress As Word)
        Dim DataByte As Byte
       
        Do                                      ' Create a loop
            DataByte = cPtr8(pFlashAddress++)   ' Read data from flash memory and increment the address
            If DataByte = 255 Then Break        ' Exit the loop if the data is 255
            HRSOutLn Dec DataByte               ' Serially transmit the data so we can see what is read
        Loop                                    ' Close the loop    
    EndProc
    
    '----------------------------------------------------------------------    
    Main:
        ReadFlash(MyFlashData) ' Read the data from flash memory and display it
        
        Stop 
    Last edited by Les; 15th January 2018 at 17:09.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  5. #5
    Developer Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,309
    Thumbs Up
    Received: 266
    Given: 110
    Total Downloaded
    1.50 GB

    0 Not allowed!

    Default Re: Replace Label with String

    For something more like what, I think, you require. Below is a procedure that will read an offset from within a flash data table. The table's name is given in the procedure, as well as the character required.

    Code:
    '
    ' A simple demo to show reading font data from a flash memory table
    ' 
        Device = 24FJ64GA002 
        Declare Xtal= 32
    
        Declare Hserial_Baud = 9600        ' USART1 baud rate
        Declare HRSOut1_Pin = PORTB.14      ' Select the pin for TX with USART1
    
        CLKDIV = 0                          ' \
        Write_OSCCONH($10)                  ' / Enable the PLL to operate the device at 32MHz
        RPOR7 = 3                           ' Make PPS Pin RP14 U1TX
                                
    '----------------------------------------------------------------------
    ' Read Font Data from a Flash Memory table
    ' Input     : pFlashAddress holds the address of the font data in flash memory
    '           : pChar holds the character's data do read
    ' Output    : None
    ' Notes     : Reads the compiler's generic Font data table which is 6 bytes for each character
    '           : Serially Transmits the data read from flash
    '
    Proc ReadFont(ByRef pFlashAddress As Word, pChar As Byte)
        Dim DataByte As Byte                        ' Holds the byte read from the font data
        Dim wCharAddress As Word                    ' Holds the calculated flash address of a character
        Dim bCharIndex As Byte                      ' Used for the length of data in the character's font
        
        wCharAddress = pFlashAddress + (pChar * 6)  ' Calculate the offset address within the font data for the character required
        
        For bCharIndex = 0 To 5                     ' Create a loop for the bytes within the character's font
            DataByte = cPtr8(wCharAddress++)        ' Read data from flash memory and increment the address
            HRSOut Hex2 DataByte, ","               ' Serially transmit the data so we can see what is read
        Next                                        ' Close the loop
        HRSOut 13    
    EndProc
    
    '----------------------------------------------------------------------    
    Main:
        ReadFont(Font_Table, "A")   ' Read the data for character "A" within the font table
        ReadFont(Font_Table, "B")   ' Read the data for character "B" within the font table
        ReadFont(Font_Table, "C")   ' Read the data for character "C" within the font table
        ReadFont(Font_Table, "Z")   ' Read the data for character "Z" within the font table
        
        Stop  
    '
    ' Load the compiler's generic font data
    '
        Include "Font.inc"
    The above program will display on the serial terminal:

    7E,11,11,11,7E,00,
    7F,49,49,49,36,00,
    3E,41,41,41,22,00,
    61,51,49,45,43,00,


    And if you look within the Font.inc file, you'll see that the data for character's "A", "B", and "C" are:

    $7E,$11,$11,$11,$7E,$00,_ '65 - A - 41
    $7F,$49,$49,$49,$36,$00,_ '66 - B - 42
    $3E,$41,$41,$41,$22,$00,_ '67 - C - 43


    and character "Z" is:

    $61,$51,$49,$45,$43,$00,_ '90 - Z - 5A

    So the data is read correctly.
    Last edited by Les; 15th January 2018 at 17:40.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  6. #6
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    765
    Thumbs Up
    Received: 16
    Given: 11
    Total Downloaded
    382.78 MB

    0 Not allowed!

    Default Re: Replace Label with String

    Thank you Les, I had managed to get something working along the same principle though not as neat as your method so will look at changing a few things.

  7. #7
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    765
    Thumbs Up
    Received: 16
    Given: 11
    Total Downloaded
    382.78 MB

    0 Not allowed!

    Default Re: Replace Label with String

    I get a compile error (missing comma or command terminated incorrectly) when I pass both a ByRef variable and a string variable as parameters to the procedure.

    For example if I use the following in the above example I get the error.

    Code:
    Proc ReadFont(ByRef pFlashAddress As Word, pString As String * 50, pChar As Byte)
    If I remove either the ByRef ie make it just a normal word variable or remove the string parameter it will compile.

  8. #8
    Developer Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,309
    Thumbs Up
    Received: 266
    Given: 110
    Total Downloaded
    1.50 GB

    2 Not allowed!

    Default Re: Replace Label with String

    Thanks for spotting that Simon. It was caused by a default not being reset properly within the loop that parses parameters, so it mistook the String as a ByRef as well. :-)

    This has now been corrected and a patch can be downloaded from here:

    Update patch for Proton24 to version 1.0.4.7

    Place the App24.exe file within the compiler's PDS directory, overwriting the existing App24.exe file.
    It is recommended that the original App24.exe be copied and saved before overwriting it (just in case).

    The default drive locations are:

    For Windows 7 64-bit or Windows 8 or Windows 10:
    C:\Program Files (x86)\ProtonIDE\PDS\

    For Windows 7 32-bit or Windows XP:
    C:\Program Files\ProtonIDE\PDS\
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  9. #9
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    765
    Thumbs Up
    Received: 16
    Given: 11
    Total Downloaded
    382.78 MB

    0 Not allowed!

    Default Re: Replace Label with String

    Thanks for the very quick response and the patch, all working now.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. How to replace potentiometer with PS2 Joystick ¿?
    By Mentcleer in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 16th February 2017, 13:56
  2. DS3231 RTC to replace DS1307 - Can't get it working
    By SimonJA in forum Proton Plus Compiler v3
    Replies: 10
    Last Post: 20th January 2009, 11:25
  3. Search and replace
    By Mark Rodgers in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 20th February 2006, 12:16
  4. Find/Replace trouble
    By Mark Rodgers in forum Mecanique - IDE
    Replies: 3
    Last Post: 6th November 2004, 10:02

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts