Any elegant way of text string handling?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default Any elegant way of text string handling?

    Hello.

    I'm making a LCD clock which uses 1602 LCD. I want to display day of the week according to RTC reading.
    However, since there are no string variables, I have to make an array, in which I put ASCII codes of letters to be written, and read them accordingly:

    Code:
    DNAME[1]=77:DNAME[2]=111: DNAME[3]=110 'Mon
    DNAME[4]=84:DNAME[5]=117: DNAME[6]=101 'Tue
    DNAME[7]=87:DNAME[8]=101: DNAME[9]=100 'Wed
    DNAME[10]=84:DNAME[11]=104: DNAME[12]=117 'Thu
    DNAME[13]=70:DNAME[14]=114: DNAME[15]=105 'Fri
    DNAME[16]=83:DNAME[17]=97: DNAME[18]=116 'Sat
    DNAME[19]=83:DNAME[20]=117: DNAME[21]=110 'Sun
    
    
    TAVAKI:
    FOR CNT=1 to 21 STEP 3
    lcdout $fe, $01, DNAME[CNT], DNAME[CNT+1],DNAME[CNT+2]
    PAUSE 1000
    NEXT CNT
    GOTO TAVAKI
    Here it works, because I've trimmed all weekday names to same length. But say if I want to have different length texts, I have to add another array, which will hold the length of the words. This is very weird, is there any means to avoid this?

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Any elegant way of text string handling?

    But say if I want to have different length texts, I have to add another array, which will hold the length of the words. This is very weird, is there any means to avoid this?

    there are many ways that have be discussed on this forum over the years

    try a forum search "embedded string" or "null terminated"
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: Any elegant way of text string handling?

    Well I've checked and there are some posts, with ASM code and referring to non-existing pbpcommunity domain.
    So as I can see, the easiest method is to use an external EEPROM or chip's built in one (if there are not much strings to be used) and build system like this - say first 32 bytes (16 words) of eeprom contain entry addresses of separate strings, and to read the stirng we launch a routine, which will start reading eeprom at X address till it reaches value, stored in next string entry address area. Code (for reading single string) should look like this

    Code:
    READ 0, startval ' read entry address of 1st string
    READ 2, nextval 'read entry address of next string
    nextval=nextval-startval 'determine string length
    
    LCDOUT $fe,$2 'set LCD start position to needed area (1st line in this case)
    FOR A=1 to nextval 'start the loop
    READ A,TXT 'read into variable
    LCDOUT $fe,TXT, $14 "Output char and move cursor to next position
    next
    Not the best, but I guess better than with dealing with ASM.

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,796


    Did you find this post helpful? Yes | No

    Default Re: Any elegant way of text string handling?

    Why not use a termination character, say 0 terminated string.

    So you only have to check if you reached the 0 value in the data area that your message is stored.

    This is what Richard suggested. No calculations required.

    Ioannis

  5. #5
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Any elegant way of text string handling?

    Nice idea, but I have to have all entries for next string marked, so this makes no big difference.....

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,796


    Did you find this post helpful? Yes | No

    Default Re: Any elegant way of text string handling?

    It sure does...

    Think about it.

    Ioannis

Similar Threads

  1. Replies: 3
    Last Post: - 3rd December 2011, 23:48
  2. How to prepare text (lots of text) for HSEROUT ?
    By Byte_Butcher in forum General
    Replies: 0
    Last Post: - 15th February 2010, 23:31
  3. Elegant "in circuit programming"
    By Ted's in forum General
    Replies: 15
    Last Post: - 1st September 2008, 00:42
  4. Interrupt handling on 16F628A
    By Mugelpower in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd January 2008, 00:20
  5. interrupt handling faster than if's?
    By mbw123 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 27th October 2006, 02:25

Members who have read this thread : 1

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