copy-string 'function'


Results 1 to 28 of 28

Threaded View

  1. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Good point!!!

    Take 2.2 .....................

    I based this off of Mr_E's simple print-string routine originally written for an LCD, adapted for my GLCD, now adapted to copy a string within the source over to a string array...basically so I can send it out with a serout or lcdout command.

    Set up for use with PIC18Fxxxx series PICs using PBP 2.50 and above (PBPL).

    Code:
    string var byte[255] : stringpos var byte : addr var long : char var byte
    'if using PIC with less than 64K flash, don't need to use PBPL, can change
    'addr from LONG to WORD
    
    ASM     'macro must be placed in program before its first use
    copystr  macro  stringcopy
    	local  thestringcopy , overthestring
    	bra overthestring
    thestringcopy
    	data  stringcopy , 0
    overthestring
    	MOVE?CW  thestringcopy , _addr
    ;It is necessary to use CN in place of CW to cover the case when the
    ;copystring statement is located above 64K (i.e. PIC18F4685, '8722, etc.etc.)
    	L?CALL  _copystring
    	endm
    ENDASM
    
    copystring:          stringpos  =  0
    copystringloop:     READCODE  addr ,  char : if char = 0 then copystringdone
                             string[ stringpos ] = char : addr = addr + 1
                             stringpos = stringpos + 1
                             if stringpos < 255 then copystringloop
    copystringdone:   string[ stringpos ] = 0 : stringpos = stringpos + 1
                             if stringpos < 254 then copystringdone
                             return
    Now the statement:

    @ copystr "TEST STRING"

    Should result in the variable array STRING with "TEST STRING" with the remainder of the array zero'd.[/QUOTE]
    Last edited by skimask; - 15th August 2008 at 04:57. Reason: Fixed post. Had bits/pieces missing from a cut-paste from a program I was using this code in...should be fixed now

Similar Threads

  1. How about String Variables?
    By mytekcontrols in forum PBP Wish List
    Replies: 40
    Last Post: - 20th January 2015, 12:53
  2. Replies: 11
    Last Post: - 12th July 2008, 02:36
  3. Embedded Strings in your Code Space
    By mytekcontrols in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 9th March 2008, 07:50
  4. Visual Basic 6 & Access 2000
    By Demon in forum Off Topic
    Replies: 33
    Last Post: - 7th September 2006, 04:39
  5. Message String Table using Readcode
    By mytekcontrols in forum Code Examples
    Replies: 2
    Last Post: - 10th July 2005, 23:17

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