transfer a string from ROM to an array


Closed Thread
Results 1 to 40 of 45

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: transfer a string from ROM to an array

    why did you say before "interrupts need to be disabled
    I was thinking that if were to read the flash using TABLPU reg and index through the ram array using fsr0 then I'm not convinced that method is interrupt proof
    but your not doing that anyway


    I expect you realise that pokecode uses twice the memory to store a string compared to da
    Last edited by richard; - 17th April 2015 at 08:52. Reason: got interrupted by customer / and lost plot

  2. #2
    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, I was not understanding why I had to increment the pointer by two when reading data ...
    I have subsituted now pokecode with da and peekcode with readcode and saved another kb .. thanks !
    Marco

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: transfer a string from ROM to an array

    this might do what you want
    note with the da method char values must be<128 ie 7 bit ascii
    just noticed I left an arraywrite in there it can/should be removed and the bit setting the 0 at end of the string was fixed too

    Code:
    '****************************************************************
    '*  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 word
    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
     
     ASM
    Loadb	 macro buffer
    	CHK?RP _cnt
     	movlw low buffer		
    	movwf FSR2L
     	movlw High buffer
     	movwf FSR2H
    
     endm
    ENDASM
    
     
     
     
     
     ARRAYWRITE buff,["123"]
    
     StartLoop: ' This loop repeats continuously just as a test.
    @ GetAddress _String1, _Addr ' Get address of String
    @ Loadb    _inbuff 
    CNT=0
     
     gosub StringOut ' Send the String
     
     Serout2 PORTb.7,84, ["inbuff "," c ",hex CNT," ",str inbuff\CNT ,13,10] ' New Line
    
    
    
    @ GetAddress _AnotherString, _Addr ' Get address of String
    @ Loadb    _inbuff 
    CNT=0
    
     gosub StringOut ' Send the String
     
     Serout2 PORTb.7,84, ["inbuff "," c ",hex CNT," ",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
     bfill:
     asm
     	CHK?RP _Char
     	movf _Char ,w
        
        movwf  POSTINC2
       
     endasm
     
     
     
     cnt=cnt+1
     Addr = Addr + 1 ' Point to next character
     goto StringOut ' Continue with rest of the string
     
     
     StringDone:
     asm
     	
     	movlw 0
        
        movwf   INDF2
      endasm   
     return
    
     
    
    
    
    
     end
    Last edited by richard; - 17th April 2015 at 11:55. Reason: fix errors

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

    Wow, thanks !
    Need a break now. I'll let you know tomorrow or monday, as I test everything.
    Marco

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: transfer a string from ROM to an array

    a cleaned up version
    Attached Files Attached Files

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


    Did you find this post helpful? Yes | No

    Default Re: transfer a string from ROM to an array

    an even better way
    Attached Files Attached Files

  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

    Hi again,
    thanks for the cleaned and full working sample.
    I'm much scared about "its not interrupt proof , other pbp functons may and do use FSR2 and TBLPTR" ....
    I'll try to ask Melabs if it's safe or not.
    Marco

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