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

    evidently I'm not explaining it well
    we never write directly to _buff we do it 'indirectly' via the 16 bit full address in fsr2 its called INDIRECT ADDRESSING read the chapter in the data sheet ,(this is how pic18's have arrays that can be bigger than a ram bank)
    bank select is not applicable to indirect addressing


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

    observe symbol table

    Code:
    inbuff  var byte[30]
     buff var byte[30]       $500
    SYMBOL TABLE
    LABEL VALUE

    _STVREN_OFF_4L 000000FE
    _STVREN_ON_4L 000000FF
    _StartLoop 00000168
    _String1 0000013E
    _String2 00000150
    _TRISH 00000F94
    _TRISL 00000F93
    _WDTEN_OFF_2H 000000FE
    _WDTEN_ON_2H 000000FF
    _WDTPS_1024_2H 000000F5
    _WDTPS_128_2H 000000EF
    _WDTPS_16384_2H 000000FD
    _WDTPS_16_2H 000000E9
    _WDTPS_1_2H 000000E1
    _WDTPS_2048_2H 000000F7
    _WDTPS_256_2H 000000F1
    _WDTPS_2_2H 000000E3
    _WDTPS_32768_2H 000000FF
    _WDTPS_32_2H 000000EB
    _WDTPS_4096_2H 000000F9
    _WDTPS_4_2H 000000E5
    _WDTPS_512_2H 000000F3
    _WDTPS_64_2H 000000ED
    _WDTPS_8192_2H 000000FB
    _WDTPS_8_2H 000000E7
    _WRT0_OFF_6L 000000FF
    _WRT0_ON_6L 000000FE
    _WRT1_OFF_6L 000000FF
    _WRT1_ON_6L 000000FD
    _WRT2_OFF_6L 000000FF
    _WRT2_ON_6L 000000FB
    _WRT3_OFF_6L 000000FF
    _WRT3_ON_6L 000000F7
    _WRTB_OFF_6H 000000FF
    _WRTB_ON_6H 000000BF
    _WRTC_OFF_6H 000000FF
    _WRTC_ON_6H 000000DF
    _WRTD_OFF_6H 000000FF
    _WRTD_ON_6H 0000007F
    _XINST_OFF_4L 000000BF
    _XINST_ON_4L 000000FF
    __18F45K20 00000001
    _bfill 0000022C
    _buff 00000500
    _inbuff 0000001A
    main 000000EA
    pauseloop 000000A6
    pauseusloop 000000C2
    ser2delay 0000007C
    serout2bit 0000004E
    serout2done 0000004A
    serout2loop 00000022
    serout2norm 00000068

  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

    buff var byte[30] $4f0 ; buff is now straddles banks 4 and 5

    _buff 000004F0 symbol table

    code still works perfectly as expected

  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

    Richard,
    the source of my doubts is that I have some unexpected behaviours and I'm trying to understand where is the problem.
    Watching the program memory, I found some "00" chars here and there in the middle of the string
    Lets' say the string "Hello",0 when I look the program memory is 48 65 6C 00 6C 6F 00
    I'm discovering now that the directive "da" is only for PIC12/16 and not for PIC18

    http://ww1.microchip.com/downloads/e...Doc/33014J.pdf

    I think I should use "db" or "data", I'm trying to understand

    "db" seems to work fine
    Last edited by Marcick; - 21st April 2015 at 08:40.

  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

    how are you looking at the pgm memory , I think something is not right

    for me the da and data directives produce exactly the same result , I left the da directive in, thinking I might try the code on a pic16f1825 for a learning experience , for 7 bit ascii data either will do (pic 18's can store 2x8 bit ,pic 16's 2x7bit )

    the relevant listings
    Code:
    0
    0013E 6854 7369 6920 00199  data "This is a string",0
              2073 2061 7473 
              6972 676E 0000
    Code:
    00013E 6854 7369 6920 00199  da "This is a string",0
                2073 2061 7473 
                6972 676E 0000

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

    Found the problem.

    I have a string like this:

    say "hello"

    I use this format do declare it, the same format I was using with arraywrite

    Code:
    @ da "say",34,"hello",34,0
    The result in program memory is that before each char 34 is added a char 00
    If I use "db" instead the result is correct.
    The pdf I linked before says that "da" is not for PIC18

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

    where ?
    da – Data ASCII.
    Generates a packed 14-bit number representing two 7-bit ASCII characters.

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: transfer a string from ROM to an array

    I think it might have something to do with the number of bytes (odd or even) in the string.
    In both of Richards examples there's an even number of bytes (16 and 22) but your Hello string there's an odd number of bytes (5). I seem to remember an issue with this being discussed in one of the 'Strings in codespace' threads some years ago.

    /Henrik.

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

    odd length strings , wastes space but not a problem


    00013E 6854 7369 6920 00199 data "This is a string1",0
    2073 2061 7473
    6972 676E 0031
    0000

    00013E 6854 7369 6920 00199 da "This is a string1",0
    2073 2061 7473
    6972 676E 0031
    0000

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

    00013E 6548 6C6C 006F 00199 da "Hello",0
    0000

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