transfer a string from ROM to an array


Closed Thread
Results 1 to 40 of 45

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    84

    Default transfer a string from ROM to an array

    Hi all,
    I'm using this code to load an array with a certain text string

    Code:
    inbuff VAR BYTE(100)  
    arraywrite inbuff,["Sample test string"]
    I have many different string in variuos parts of the program and this code consumes a lot of space, so I would like to optimize it using macros .

    It's easy to store the string in code space and then with a macro retrieve the address and read it:

    Code:
    ROM_String1:       PokeCode "Sample test string",0
    
    
    ; macro to retrieve the address
    
    @getaddr	macro Text, Addr
    @ 	movlw low Text
    @ 	movwf Addr
    @ 	movlw High Text
    @ 	movwf Addr + 1
    @ endm
    
    
    ; code
    	@ getaddr _ROM_String1, _w0
      repeat
        peekcode w0, x
        if x then 
          debug x
          w0=w0+2
        endif
      until x=0                                     ' print till end of string '0'
    
    Sb00:
    	.....
    Now I have some difficulties to continue: instead of print the string, I need to store it in RAM, the same things that does ArrayWrite.
    So the macro should be modified to accept as parameters, the source ROM string and the destination address in RAM
    Something like

    Code:
    @ LoadStr _ROM_CfgString, _inbuff
    So calling the macro I can specify any string stored in ROM and any RAM destination where to put it.
    Could anybody help me to complete the macro ?
    Thanks
    Marco

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


    Did you find this post helpful? Yes | No

    Default Re: transfer a string from ROM to an array

    Hi,
    How about:
    Code:
    inBuff VAR BYTE[100]
    i VAR BYTE
    
    i = 24         ' Start putting the string at inBuff[24] for example  
    repeat
      peekcode w0, x
      if x then 
        inBuff[i] = x
        debug x
        w0=w0+2
      endif
      i=i+1
    until x=0
    /Henrik.

  3. #3
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    84


    Did you find this post helpful? Yes | No

    Default Re: transfer a string from ROM to an array

    Hi Enrik, thanks,
    inbuff should be a parameter passed to the macro and not a fixed address.

    I have something like this:

    Code:
    inBuff VAR BYTE[100]
    Outbuff VAR BYTE[100]
    Testbuff VAR BYTE[200]
    etc etc

    I want that Inbuff, Outbuff, TestBuff is a parameter of the macro, so the string can be written anywhere

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    Did you find this post helpful? Yes | No

    Default Re: transfer a string from ROM to an array

    I'm not very good at assembly language but can't you just pass it the variable name, like _inBuff, which would be the "start adress" of the array?

    /Henrik.

  5. #5
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    84


    Did you find this post helpful? Yes | No

    Default Re: transfer a string from ROM to an array

    There must be some awful mistakes, I can't get this code working

    Code:
    #CONFIG
    	CONFIG	OSC = IRCIO67	    ;Internal oscillator block, port function on RA6 and RA7
    	CONFIG	WDT = ON	    	;WDT enabled
    	CONFIG	WDTPS = 64	    	;1:64
    	CONFIG	PWRT = ON	    	;PWRT enabled
    	CONFIG	BOREN = BOHW	    ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
    	CONFIG	BORV = 3	    	;VBOR set to 2.1V
    	CONFIG	MCLRE = OFF	    	;RE3 input pin enabled; MCLR disabled
    	CONFIG	LPT1OSC = OFF	    ;Timer1 configured for higher power operation
    	CONFIG	PBADEN = OFF	    ;PORTB<4:0> pins are configured as digital I/O on Reset
    	CONFIG	XINST = OFF	    	;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    	CONFIG	LVP = OFF	    	;Single-Supply ICSP disabled
    	CONFIG	STVREN = ON
    	CONFIG	CP0 = ON
    	CONFIG	CP1 = ON
    	CONFIG	CP2 = ON
    	CONFIG	CP3 = ON
    #ENDCONFIG
    
    	Define 		USE_LFSR 	1
    	DEFINE		OSC			8
    	DEFINE		DEBUG_REG	PORTB
    	DEFINE		DEBUG_BIT	4
    	DEFINE		DEBUG_BAUD	9600
    	DEFINE		DEBUG_MODE	0		
    	
    	OSCCON		=%01110000			
    	Led			VAR PORTB.3
    	inbuff		VAR BYTE[100]
    	x			VAR BYTE
    	y			VAR BYTE
    	LS0 		VAR Word
    	LS1 		VAR Word
    
    	goto	Start
    
    ASM
    LoadString	 macro Text, Dest
     	movlw low Text
    	movwf _LS0
     	movlw High Text
     	movwf _LS0 + 1
    	movlw low Dest
    	movwf _LS1
    	movlw High Dest
    	movwf _LS1 + 1
     	L?CALL   _Lstr
     endm
    ENDASM
    
    Lstr:
    	y=0
      	repeat
        	peekcode LS0, x
    		LS1(y)=x
    		y=y+1
    	    LS0=LS0+2
        until x=0                                     
      return
    
    
    Start:
    	@ LoadString _ROM_CfgString, inbuff
    	debug str inbuff\100,13,10
    	pause 500
    	high led
    	pause 500
    	low led
    	goto start
    
    end
    
    ROM_CfgString:       PokeCode "This a test string",0

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


    Did you find this post helpful? Yes | No

    Default Re: transfer a string from ROM to an array

    try a forum search "embedded string"

Similar Threads

  1. String of characters(array) to decimal value
    By tacbanon in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 20th June 2012, 14:30
  2. Replies: 3
    Last Post: - 3rd December 2011, 22:48
  3. Array of string to send with TX int ?
    By amgen in forum General
    Replies: 18
    Last Post: - 18th August 2011, 16:56
  4. How to send a string with another string inside it?
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th May 2011, 17:11
  5. Manipulation of string array
    By Benny007 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 23rd April 2008, 20:50

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