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


    Did you find this post helpful? Yes | No

    Default Re: transfer a string from ROM to an array

    What I can't find how to do, is to pass to the macro the address of an array.

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


    Did you find this post helpful? Yes | No

    Default Re: transfer a string from ROM to an array

    as henrik said
    inBuff VAR BYTE[100]


    in asm the array address is
    _inBuff

    or give a new name

    ASM
    mybuff =_inBuff
    ENDASM
    note label in col 0

    make sure you don't overrun your buffer

  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, I undestand, but I can't put togheter something of working. If you want to have a look to this code, you'll see in my comments where are my doubts.
    Anyway the code doesn't compile and give errors ...

    Code:
    	inbuff		VAR BYTE[100]
    	x			VAR BYTE
    	y			VAR BYTE
    	LS0 		VAR WORD
    	LS1			VAR WORD
    
    Lp1:
    	@ LoadInbuff _ROM_CfgString, _Inbuff		; I would like to transfer the ROM string in RAM Inbuff
    	debug str inbuff\100,13,10
    	goto lp1
    
    ASM
    LoadInbuff	 macro Text, Dest
    	CHK?RP _LS0
     	movlw low Text		; here I load in LS0 the ROM address of the source string
    	movwf _LS0
     	movlw High Text
     	movwf _LS0 + 1
    	CHK?RP _LS1			; here I suppose to load in LS1 the address of the destination buffer
     	movlw low Dest		; but I feel something is wrong
    	movwf _LS1
     	movlw High Dest
     	movwf _LS1 + 1
    	L?CALL   _Lstr
     endm
    ENDASM
    
    Lstr:
    	y=0
      	do
        	peekcode LS0, x
    		; --->>> what to do here to write the value x to the destination buffer ??
    		if x=0 then exit
    		y=y+1
    	    LS0=LS0+2
        loop
      return
    
    
    
    ROM_CfgString:       PokeCode "This a test string",0

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


    Did you find this post helpful? Yes | No

    Default Re: transfer a string from ROM to an array

    add this to your code
    ARRAYWRITE inbuff,3,,["123"]

    and then look at the lst file generated

    see how arraywrite works
    01487 LIST
    000004 C00C FFE9 01488 ARRAYWRITE movff R5, FSR0L ; Put the array pointer into FSR0
    000008 C00D FFEA 01489 movff R5 + 1, FSR0H
    00000C 6EEE 01490 movwf POSTINC0 ; Put the char into the array and bump up the address
    00000E CFE9 F00C 01491 movff FSR0L, R5 ; Save new pointer
    000012 CFEA F00D 01492 movff FSR0H, R5 + 1
    the array address goes in like this


    C:\PBP3\EXAMPLES\MARCICK.PBP 00074 ARRAYWRITE inbuff,3,,["123"]
    00192 ARRAYWRITENAME?B _inbuff
    M MOVE?CW _inbuff, R5
    M ifdef USE_LINKER
    M CHK?RP R5
    M movlw low (_inbuff)
    M movwf R5
    M movlw high (_inbuff)
    M movwf (R5) + 1

    you need to emulate this using your own vars don't use r5 of course


    interrupts will need to be disabled too


    ps the forum totally destroys white space you need to look at your xxx.lst file to make it out properly
    Last edited by richard; - 15th April 2015 at 13:49. Reason: clean up

  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

    Richard,
    Thanks for your time but .. if you have some more ... could you please take my sample above and correct it so it works ?
    It's two days I'm turning crazy.
    Anyway thank you
    Marco

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


    Did you find this post helpful? Yes | No

    Default Re: transfer a string from ROM to an array

    Code:
    'pic18f45k20
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2015 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 4/14/2015                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2015 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 4/14/2015                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
     #CONFIG
      CONFIG  FOSC = INTIO67
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRT = OFF
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 18
      CONFIG  WDTEN = ON
      CONFIG  WDTPS = 512
      CONFIG  CCP2MX = PORTC
      CONFIG  PBADEN = OFF
      CONFIG  LPT1OSC = OFF
      CONFIG  HFOFST = ON
      CONFIG  MCLRE = ON
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG
    
    
      define OSC 64
     osccon=$70   '64 mhz
     OSCTUNE.6=1
     
     
     
     pause 2000
     
    Serout2 PORTb.7,84,["ready",13,10] 
     
    Addr var word
     Char var byte
     cnt var byte
    inbuff  var byte[30]
    buff var byte[30]
     Clear
    
     
    
    
    
     goto StartLoop ' Required
    
     String1:
     @ da "This is a string",0
    
     AnotherString:
     @ da "Here is another string",0
    
     '------------GetAddress Macro - Location insensitive -------------------------
     ASM
    GetAddress macro Label, Wout ; Returns the Address of a Label as a Word
       CHK?RP Wout
       movlw low Label
       movwf Wout
       movlw High Label
       movwf Wout + 1
       endm
     ENDASM
    
    
     StartLoop: ' This loop repeats continuously just as a test.
    @ GetAddress _String1, _Addr ' Get address of String
     cnt=0
     gosub StringOut ' Send the String
     Serout2 PORTb.7,84, [13,10] ' New Line
     Serout2 PORTb.7,84, ["inbuff ",str inbuff\cnt ,13,10] ' New Line
    
    
    @ GetAddress _AnotherString, _Addr ' Get address of String
     cnt=0
     gosub StringOut ' Send the String
     Serout2 PORTb.7,84,[13,10] ' New Line
     Serout2 PORTb.7,84, ["inbuff ",str inbuff\cnt ,13,10] ' New Line
     pause 500
     goto StartLoop ' Repeat
    
    
     StringOut: ' Send the string out via Hserout
     Readcode Addr, Char ' Get a character
     if Char = 0 then StringDone ' Look for Null char, Stop if found
     buff[cnt]=char
     cnt=cnt+1
     Serout2 PORTb.7,84, [Char] ' Send char
     Addr = Addr + 1 ' Point to next character
     goto StringOut ' Continue with rest of the string
     StringDone:
     ARRAYWRITE inbuff,cnt,,[str buff]
     return
    
    
     end
    I do it this way , and use the bounds checking features of arraywrite

  7. #7
    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

    Well, any help is appreciated, so thank you anyway, but this is not what I'm asking.
    My intent is not to use Arraywrite because consumes a lot of space.
    With this sample code that now works I transfer a ROM string to an array, but I want also the destination array to be a parameter passed to the macro.
    So with a single macro I could transfer to inbuff or testbuff or any buffer Is declared.

    Code:
    	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	
    
    	inbuff		VAR BYTE[100]
    	x			VAR BYTE
    	y			VAR BYTE
    	LS0 		VAR WORD
    	LS1			VAR WORD
    	goto Lp1
    
    ASM
    LoadInbuff	 macro Text
    	CHK?RP _LS0
     	movlw low Text		; here I load in LS0 the ROM address of the source string
    	movwf _LS0
     	movlw High Text
     	movwf _LS0 + 1
    	L?CALL   _Lstr
     endm
    ENDASM
    
    Lstr:
    	y=0
      	do
    	    	peekcode LS0, x
    		inbuff(y)=x
    		if x=0 then exit
    		y=y+1
    		LS0=LS0+2
    	loop
    	return
    
    
    Lp1:
    	@ LoadInbuff _ROM_CfgString
    	debug str inbuff\100,13,10
    	goto lp1
    
    
    ROM_CfgString:       PokeCode "This a test string",0

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