Handling a lot of text data, any simple and practical ways?


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,160


    Did you find this post helpful? Yes | No

    Default Re: Handling a lot of text data, any simple and practical ways?

    Thanks!
    I had a almost similar approach -
    The text is stored in EEPROM part of the IC, in series.
    There is a 40 byte area at beginning in EEPROM, which
    has offset and length entries for these text messages
    so all I have to do, to say display "Set Time" is call a routine like

    Code:
    READ 1,A 'read offset
    READ 2,B 'read length
    FOR C=A to A+B 'define a loop from this to that
    READ C,D 'read eeprom at needed value
    LCDOUT $FE,D,$14 'Display char and move cursor to next char
    NEXT
    But for some reasons it does not works, seems like that LCDOUT on initialization, resets the offset set by $14 (move cursor right)

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,627


    Did you find this post helpful? Yes | No

    Default Re: Handling a lot of text data, any simple and practical ways?

    Code:
    LCDOUT $FE,D,$14 'Display char and move cursor to next char
    That line of code does NOT do what the comment says.

    You're telling it to interpret whatever you read from EEPROM (into the D variable) as a command, then you're sending a constant $14 which it will interpret as data and print whatever character that code corresponds to (see datasheet).

    To do what the comment says it would look like this:
    Code:
    LCDOUT D, $FE, $14
    With that said, the adress counter in the HD44780 will automatically increment each time you write to DDRAM (ie send it a byte not preceded by $FE) so by doing the above you will end up with a blank space between the characters.

  3. #3
    Join Date
    Feb 2013
    Posts
    1,160


    Did you find this post helpful? Yes | No

    Default Re: Handling a lot of text data, any simple and practical ways?

    Oh thanks, will give it a try!

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,720


    Did you find this post helpful? Yes | No

    Default Re: Handling a lot of text data, any simple and practical ways?

    on a 16f like this

    Code:
    ;16f1825#CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_OFF &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF
    #ENDCONFIG
    
    
    DEFINE OSC 32    
        OSCCON=$70
        ANSELA=0
        ANSELC=0
        TRISA = %001110
        trisc = %11100010     ' set PORTC I/O
        Strings CON EXT
    
    
        i VAR BYTE
        Char VAR BYTE
        ctemp  VAR WORD
        StringNumber VAR BYTE
        StartAddress VAR WORD
        rand      VAR WORD
        lata.0=1 
        DEFINE DEBUG_REG PORTA
        DEFINE DEBUG_BIT 0      ;  if not used for pwr  
        DEFINE DEBUG_BAUD 9600
        DEFINE DEBUG_MODE 0     
        pause 2000
        Debug "Start",13 ,10  
    Goto OverStrings
    ASM
    Strings
        ; Strings, fixed length, 20 characters including null terminator.
        ; Actual string terminatesends with a NULL and is then padded to exactly 20 chars.
        da "Set Year", 0, "           "    ; 0
        da "Set Month", 0, "          "    ; 1
        da "Set Date", 0, "           "    ; 2
        da "Set day of week", 0, "    "    ; 3
        da "Set Hour", 0, "           "    ; 4
        da "Set Minute", 0, "         "    ; 5 
        da "Set alarm mode", 0, "     "    ; 6
        da "Off", 0, "                "    ; 7
        da "On all week", 0, "        "    ; 8
        da "On without weekends", 0, ""    ; 9
        da "Set alarm hours", 0, "    "    ; 10
        da "Set alarm minutes", 0, "  "    ; 11
        da "Set display format", 0, " "    ; 12
        da "Imperial (12Hr/F)", 0, "  "    ; 13
        da "Metric (24Hr/C)", 0, "    "    ; 14
        da "Display brightness", 0, " "    ; 15
        da "Auto", 0, "               "    ; 16
        da "25%", 0, "                "    ; 17
        da "50%", 0, "                "    ; 18
        da "75%", 0, "                "    ; 19
        da "100%", 0, "               "    ; 20
    ENDASM
    OverStrings: 
    
    
    Start:
        Debug "Program start",13,10 
        Debug "Address of first string: $", HEX4 Strings, 13 ,10
    
    
    Action:    
         RANDOM  rand 
        StringNumber = rand//20                               ' Select which string to print
        GOSUB PrintString                               ' And, you guessed it, go print it.
         PAUSE 1000
        goto  Action
    END
    
    
    PrintString:   
        StartAddress = Strings + (StringNumber * 11)    ' Precalculate address of first char of string in question
        For i = 0 to 19                                 ' Maximum string length is 20 characters
            ReadCode (StartAddress + i), CTEMP           ' Get a char from string in question.
          Char = (CTEMP>>7) 
            IF (Char = 0) THEN EXIT                     ' Break out if char is NULL
            Debug Char                                   ' Otherwise print it
         Char = CTEMP&$7f        
           IF (Char = 0) THEN EXIT                     ' Break out if char is NULL
            Debug Char                                ' Otherwise print it
        NEXT
    RETURN
    or if all that padding is troubling , using random length null terminated strings
    Code:
    ;16f1825#CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_OFF &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF
    #ENDCONFIG
    
    
    DEFINE OSC 32
        OSCCON=$70
        ANSELA=0
        ANSELC=0
        TRISA = %001110
        trisc = %11100010     ' set PORTC I/O
        Strings CON EXT
        i VAR BYTE
        Char VAR BYTE
        ctemp  VAR WORD
        rand   VAR WORD
        StringNumber VAR BYTE
        StartAddress VAR WORD
        isa   VAR WORD
        lata.0=1 
        DEFINE DEBUG_REG PORTA
        DEFINE DEBUG_BIT 0      ;  if not used for pwr  
        DEFINE DEBUG_BAUD 9600
        DEFINE DEBUG_MODE 0     
        pause 2000
        Debug "Start",13 ,10  
    Goto OverStrings
    ASM
    Strings
        ;  string terminates with a NULL 
        da "Set Year", 0     ; 0
        da "Set Month", 0     ; 1
        da "Set Date", 0    ; 2
        da "Set day of week", 0    ; 3
        da "Set Hour", 0     ; 4
        da "Set Minute", 0     ; 5 
        da "Set alarm mode", 0     ; 6
        da "Off", 0    ; 7
        da "On all week", 0     ; 8
        da "On without weekends", 0   ; 9
        da "Set alarm hours", 0    ; 10
        da "Set alarm minutes", 0     ; 11
        da "Set display format", 0    ; 12
        da "Imperial (12Hr/F)", 0    ; 13
        da "Metric (24Hr/C)", 0    ; 14
        da "Display brightness", 0    ; 15
        da "Auto", 0    ; 16
        da "25%", 0     ; 17
        da "50%", 0    ; 18
        da "75%", 0     ; 19
        da "100%", 0     ; 20
        dw 3            ;eof
    ENDASM
    OverStrings:
    
    
    Start:
        Debug "Program start",13,10 
        Debug "Address of first string: $", HEX4 Strings, 13 ,10
    
    
    Action: 
        RANDOM  rand 
        StringNumber = rand//20                             ' Select which string to print
        GOSUB findIndex  
        GOSUB PrintString                               ' And, you guessed it, go print it.
        PAUSE 1000
        goto  Action
    END
    
    
    findIndex:
        isa    = Strings
        while StringNumber
            ReadCode isa, CTEMP
            isa=isa+1
            if  CTEMP ==3 then 
                isa=0
                return
            endif
            if (CTEMP.highbyte==0) then  
                StringNumber=StringNumber-1
                if    StringNumber == 0 then  return
            endif
        wend
    return 
    
    
    PrintString: 
        if  isa then
            Debug 13,10
            For i = 0 to 19                                 ' Maximum string length is 20 characters
                ReadCode (isa + i), CTEMP           ' Get a char from string in question.
                Char = (CTEMP>>7) 
                IF (Char = 0) THEN EXIT                     ' Break out if char is NULL
                Debug Char                                   ' Otherwise print it
                Char = CTEMP&$7f        
                IF (Char = 0) THEN EXIT                     ' Break out if char is NULL
                Debug Char                                ' Otherwise print it
            NEXT
        endif
    RETURN
    Name:  Screenshot 2021-09-13 141521.jpg
Views: 1247
Size:  79.6 KB
    Last edited by Ioannis; - 13th September 2021 at 22:59.
    Warning I'm not a teacher

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,627


    Did you find this post helpful? Yes | No

    Default Re: Handling a lot of text data, any simple and practical ways?

    Thanks for stepping in Richard, I should've mentioned my example was for 18F series of course. Yeah, the padding... It's a tradeoff, either waste memory or waste some time :-)

    In your code I see
    Code:
    if (CTEMP.highbyte==0) || (CTEMP.highbyte ==0) then
    I suppose one of those should be CTEMP.lowbyte, right?

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,720


    Did you find this post helpful? Yes | No

    Default Re: Handling a lot of text data, any simple and practical ways?

    I suppose one of those should be CTEMP.lowbyte, right?
    ̶y̶e̶s̶ ̶,̶ ̶c̶o̶p̶y̶ ̶p̶a̶s̶t̶e̶ ̶t̶r̶a̶p̶ ̶f̶o̶r̶ ̶t̶h̶e̶ ̶i̶n̶o̶b̶s̶e̶r̶v̶a̶n̶t̶

    its a pity the the forum edit restraints are so limiting

    needs to be this , adding lowbyte breaks it
    if (CTEMP.highbyte==0) then
    Last edited by richard; - 13th September 2021 at 07:10.
    Warning I'm not a teacher

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,720


    Did you find this post helpful? Yes | No

    Default Re: Handling a lot of text data, any simple and practical ways?

    adding lowbyte breaks it
    i remember it now , if you really want to be sparing with flash space odd length strings must not have the ,0 termination
    the assembler adds the 0 for odd lengths automatically. the code then needs to check lowbyte for 0-ness

    if you add the ,0 you wind up with 3 nulls in a row to account for hence only a check of highbyte works
    Warning I'm not a teacher

Similar Threads

  1. Any elegant way of text string handling?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd November 2020, 17:21
  2. Replies: 11
    Last Post: - 9th March 2020, 13:37
  3. Serious Help Needed-Tried a Lot & Now I am Here
    By Megahertz in forum Schematics
    Replies: 3
    Last Post: - 17th December 2009, 13:12
  4. Serial problem with a lot of chips
    By The Master in forum Off Topic
    Replies: 1
    Last Post: - 20th October 2007, 13:55
  5. Writing serial data to text file
    By TurboLS in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd March 2005, 23:09

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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