About writing word variables into the eeprom


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    969


    Did you find this post helpful? Yes | No

    Default

    Since you're dealing with word variables, the size is known to be 2bytes on the PIC. So, something like this will work

    Code:
    SaveArray:
    FOR ArrayPosition = 0 TO 20-1
        WRITE ArrayPosition*2,Array[ArrayPosition].Byte0,Array[ArrayPosition].Byte1
    Next
    return
    
    ReadArray:
    FOR ArrayPosition = 0 TO 20-1
        READ ArrayPosition*2,Array[ArrayPosition].Byte0,Array[ArrayPosition].Byte1
    Next
    return

  2. #2
    Ted's's Avatar
    Ted's Guest


    Did you find this post helpful? Yes | No

    Default

    I disagree here.

    WRITE ArrayPosition*2,Array[ArrayPosition].Byte0,Array[ArrayPosition].Byte1

    is for ArrayPosition = 0

    WRITE 0,Array[0].Byte0,Array[0].Byte1

    ...

    is for ArrayPosition = 19

    WRITE 38,Array[19].Byte0,Array[19].Byte1


    According to the manual, to write a word, each of the 2 bytes that make up the word must be written separately:
    w Var Word
    WRITE 0,w.BYTE0
    WRITE 1,w.BYTE1

    in other words, WRITE does not accept 3 arguments.

  3. #3
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    969


    Did you find this post helpful? Yes | No

    Default

    Ted, you're right on this. I goofed. But you got the idea though

  4. #4
    Ted's's Avatar
    Ted's Guest


    Did you find this post helpful? Yes | No

    Default

    Yes. But it does not seem to be efficient enough.

    A one or two-liner should be enough. Maybe using the remainder // ?

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    When you say efficient, do you mean speed or code size?
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    If you alias the Word array as a Byte array, you can just write 1 byte at a time in the loop.
    Code:
    arraysize  CON 20
    Array      VAR WORD[arraysize]
    
    @ByteArray = _Array
    ByteArray  VAR BYTE EXT
    
    FOR ArrayPosition = 0 TO (arraysize*2-1)
        WRITE ArrayPosition, ByteArray(ArrayPosition)
    NEXT ArrayPosition
    DT

  7. #7
    Ted's's Avatar
    Ted's Guest


    Did you find this post helpful? Yes | No

    Default

    When you say efficient, do you mean speed or code size?
    The latter.

  8. #8
    Ted's's Avatar
    Ted's Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    If you alias the Word array as a Byte array, you can just write 1 byte at a time in the loop.
    Code:
    arraysize  CON 20
    Array      VAR WORD[arraysize]
    
    @ByteArray = _Array
    ByteArray  VAR BYTE EXT
    
    FOR ArrayPosition = 0 TO (arraysize*2-1)
        WRITE ArrayPosition, ByteArray(ArrayPosition)
    NEXT ArrayPosition
    I do not understand your code. Please comment.

Similar Threads

  1. Read/Write Problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th February 2010, 02:51
  2. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 08:25
  3. DS2760 Thermocouple Kit from Parallax in PicBasicPro
    By seanharmon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th July 2008, 00:19
  4. calculation problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2006, 16:23
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 20:59

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