Embedded Strings in your Code Space


Closed Thread
Results 1 to 40 of 50

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    mytekcontrolsm,

    Using a Lookup for strings can use up a huge amount of code. And I believe I may have the solution you're looking for.

    How to store and retrieve strings in Code Space

    Another person that I helped out a while back had his 877 completely maxed out with Lookups for strings to be displayed on an LCD. After converting them to the STRINGS in CODE format, it only took up 1.5K words. Leaving 6.5K for more program. We were both amazed.

    And, I too will not be Jumping ship anytime soon. PBP is just to good.

    Darrel

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Nice job Darrel, and thanks for the excellent resource. I've used several of
    your routines on various projects.

    Here's something similar for the 18F series.
    Code:
    DEFINE LOADER_USED 1
    DEFINE OSC 4
    
    ptr_pos	VAR BYTE
    temp	VAR BYTE
    x	VAR BYTE
    
    Main:
       CALL USART_Init
       ptr_pos = 0
       CALL Start
       ptr_pos = 16
       CALL Start
       ptr_pos = 48
       CALL Start
       ptr_pos = 176
       CALL Start
    
    Done:
       GOTO Done
        
    ASM
    _USART_Init
       movlw   B'00100100'   ;initialize USART
       movwf   TXSTA	 ;8-bit, Async, High Speed
       movlw   .25           ;value for 9600 bps @ 4MHz
       movwf   SPBRG	 ;set SPBRG for 9600 bps @ 4MHz
       movlw   B'10010000'   ;enable USART
       movwf   RCSTA
       return
    
    ;----Lookup & send text messages--------------------------
    _Start
       movlw   UPPER msg_table
       movwf   TBLPTRU
       movlw   HIGH msg_table
       movwf   TBLPTRH
       movlw   LOW msg_table
       movwf   TBLPTRL
       movf    _ptr_pos,W	;prt_pos must hold message address
       addwf   TBLPTRL,F
       clrf    WREG
       addwfc  TBLPTRH,F
       addwfc  TBLPTRU,F
    
    Next_Char
       tblrd   *+
       movff   TABLAT,_temp
       bra     Test_EOM      ;test for EOM character
    	
    Continue
       movf	  _temp,W	 ;move temp to w
       movwf  TXREG		 ;send it
       btfss  TXSTA,TRMT	 ;wait for data TX
       goto   $-2
       bra	  Next_Char      ;fetch next message character from table
    	
    Test_EOM
       movlw  "~"            ;check for EOM character
       cpfseq  _temp, 1	 ;compare temp with w, if temp = ~ then end			
       bra     Continue      ;no EOM, so continue
       movlw   "\r"		 ;move data into TXREG
       movwf   TXREG	 ;send carriage return
       btfss   TXSTA,TRMT	 ;wait for data TX
       goto    $-2	
       movlw   "\n"		 ;move data into TXREG
       movwf   TXREG	 ;send line feed
       btfss   TXSTA,TRMT	 ;wait for data TX
       goto    $-2
       return                ;finished with message, return to caller
    ENDASM
    
    ASM
    msg_table	; Message strings
       data	" Message #1~    ";Message #1 starts at msg_table 0
       data	" Message #2~    ";Message #2 starts at msg_table 16, etc,
       data	" Message #3~    ";32
       data	" Message #5~    ";48
       data	" Message #6~    ";64
       data	" Message #7~    ";80
       data	" Message #8~    ";96
       data	" Message #9~    ";112
       data	" Message #10~   ";128
       data	" Message #11~   ";144
       data	" Message #12~   ";160
       data	" Message #13~   ";176
    ENDASM
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Now there's an endorsement I can be proud of.

    Thanks Bruce!

  4. #4
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Smile I like it!

    Thanks Darrel and Bruce for your great examples. I would have to say I like Darrel's approach the best, since it seems less cryptic as to what the messages are (i.e; you can give them meaningfull names). Also I like the idea that they can be located anywhere in the program (kinda like my 6502 example). However I am using an 18F252 for my project, and apparently this approach wont work with a 16 bit processor. Any ideas how this could be changed?

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Code:
    ' Text message addresses w/specific names
    Intro CON 0
    PumpOn CON 16
    PumpOFF CON 32 ' etc,,
    
       ptr_pos = Intro     ' print intro message
       CALL Start
       ptr_pos = PumpON ' print pump on message, etc,,,
       CALL Start
    You now have meaningful names for your strings. It's not that cryptic once
    you've played with it a bit. The 18F series are easier to code in .asm than
    16F parts.

    Make your strings as long as you like. That was just a quick/simple example.

    I don't have an example for placing strings all over code space since I would
    never do that. PBP library functions & my app code get first pick. Huge
    chunks of text messages get the left-overs at the bottom...;o]
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Strings updated.

    Hi again Michael,

    I guess it was about time anyhow. Haven't updated it since 2003.

    I've modified the Strings program to be able to work with 16-bit devices.

    Between Bruce's example and the new one, I'm sure you'll get what you need.

    It's still in the same place ... How to store and retrieve strings in Code Space

    Best regards,
       Darrel

  7. #7
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Question I would like to use Bruce's message table code, but...

    Hi Bruce,

    I have been studying your code that you posted here on doing message tables from assembly code, and quite frankly I am baffled by parts of it. This wouldn't be problem if I could use it as is, but I really need to have the pointer increments to be by 1 (i.e.; 0,1,2,3,4,5,6, ect.).

    Here are some snippits of your code with some questions I have next to them. If you get a chance can you please explain what is going on?

    Code:
    ; This section appears to be locating the message table, but Im not
    ; really sure specifically what is going on especially with the first part
    ; where you are moving Upper msg_table into TBLPTRU
    ; (what is UPPER? I've used HIGH and LOW before, but never UPPER).
    ; TBLPTR is obviously short for Table Pointer.
    
       movlw   UPPER msg_table 
       movwf   TBLPTRU
       movlw   HIGH msg_table
       movwf   TBLPTRH
       movlw   LOW msg_table
       movwf   TBLPTRL
    
    ; Now here we seem to be adding an offset into the message table using
    ; the same pointers we previously set to what I am asuming is the base
    ; address of our message table. This is where the beginning of a particular
    ; message resides within the table (correct?). Now here comes the questions
    ; of particular interest to me; does the fact that your pointers are in 16 byte
    ; increments mean that each message string can only be up to 16 bytes long?
    ; Or can the pointer be changed to any increment desired?
    
      movf    _ptr_pos,W	;prt_pos must hold message address
       addwf   TBLPTRL,F
       clrf    WREG
       addwfc  TBLPTRH,F
       addwfc  TBLPTRU,F
    
    ; Ok now that we have our index to a message set, we can begin retrieving
    ; the characters one by one, until we see the EOM character "~". What is
    ; tblrd   *+ or more specifically *+ (is this doing a read and then increment?)
    ; Oh and what is "goto   $-2" doing? (specifically $-2).
    
    Next_Char
       tblrd   *+
       movff   TABLAT,_temp
       bra     Test_EOM      ;test for EOM character
    	
    Continue
       movf	  _temp,W	 ;move temp to w
       movwf  TXREG		 ;send it
       btfss  TXSTA,TRMT	 ;wait for data TX
       goto   $-2
       bra	  Next_Char      ;fetch next message character from table
    	
    ; This part is fairly obvious, although there are some more of those $-2
    ; which I don't understand the purpose of, and what does "\r"
    ; and "\n" do? Actually to be more specific since I can see your comments,
    ; what my question really is; what or how does moving a literal of "\r" into
    ; W actually move the data (which I assume is a character from the table).
    
    Test_EOM
       movlw  "~"            ;check for EOM character
       cpfseq  _temp, 1	 ;compare temp with w, if temp = ~ then end			
       bra     Continue      ;no EOM, so continue
       movlw   "\r"		 ;move data into TXREG
       movwf   TXREG	 ;send carriage return
       btfss   TXSTA,TRMT	 ;wait for data TX
       goto    $-2	
       movlw   "\n"		 ;move data into TXREG
       movwf   TXREG	 ;send line feed
       btfss   TXSTA,TRMT	 ;wait for data TX
       goto    $-2
       return                ;finished with message, return to caller
    If I was better versed in the assembly aspects of the 18F series I could probably figure this out on my own, but I only recently began working with this series of PIC chips.

    Any help you can offer is appreciatted.
    Thanks,

  8. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Michael,

    Download the PICmicro® 18C MCU Family Reference Manual... or just the chapters you need from here;

    http://www.microchip.com/stellent/id...GE&nodeId=2054

    There's a whole section on table read/write with detailed explanations that should answer every question you have.

    Much easier than me re-typing it all. If you have questions after reading section 8 let me know.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 08:25
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 22:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 9th December 2008, 00:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  5. Please help with storing strings in codespace
    By g-hoot in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th May 2008, 02:02

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