word arrays and eeprom


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615

    Unhappy word arrays and eeprom

    Hi, everybody, and especially Mel.

    A happy new year for everyone

    To have a great start for the year, I have a big headache upon 16 bits arrays and EEPROM ...

    see: numbers are supposed to be stored highbyte first in even locations ... simple !

    yes, but have a look to the few lines attached ...

    yes, it's fun!!

    Alain
    Attached Files Attached Files

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


    Did you find this post helpful? Yes | No

    Default

    Hi Alain,

    By using that type of notation, you are actually changing the type of array that PBP uses.

    So, even though you have a WORD array to begin with, when you use ....

    WRITE 2, Voiesafe.Lowbyte[1]

    You are now accessing the array as if it were made up of bytes.
    The ORIGIN of the array becomes the Lowbyte of the word in location 0. Then the value in parenthesis indicates the number of bytes relative to that origin.

    It's like when you use this type of statement.

    PORTB.0[1] = 1

    This turns PORTB into an array of BITs, starting at bit 0. The statement would set on PORTB.1 to 1

    PORTB.5[1] = 1

    This bit array starts at PORTB.5, so that statement would set PORTB.6 to 1

    As for your program being OK with it. It's only because you are expecting to see the same valeues in each location. If you were trying to put different values in each location you would see the problem.

    One way to fix the problem is to use a temporary variable that can then be used with the lowbyte/highbyte type notation.

    Temp = Voiesafe[1]
    WRITE 1, Temp.Highbyte
    WRITE 2, Temp.Lowbyte

    Using it in a for/next loop will make things even eaiser.


    HTH,
        Darrel

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Smile

    Hi Darrel,

    Thank you for this good explanation. this has made me remenber PBP is widely using indirect addressing ...

    Program has been corrected to your way.

    IF you were interested in ( it's a 4 Channel R/C Failsafe system ...with auto or manual control recovery ) - there is a lot of programming tricks upon dealing with R/C signals.

    if so, see attached file.

    Thanks again

    Alain
    Attached Files Attached Files

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


    Did you find this post helpful? Yes | No

    Default

    Great! I'm glad it made sense to you.

    I was looking at your program, and frankly, I can't make heads or tails of it. Only because I can't understand french.

    But I did see the EEPROM write routine, and I think there may still be a problem.
    Code:
    '******************************************
    'Sauvegarde en EEPROM
    '******************************************
    
    	WRITE 0, mode
    
    	FOR I = 1 TO 4
    
    	WRITE I+1, Echantillon.Lowbyte
    	WRITE I,   Echantillon.Highbyte
    	Echantillon	= Voiesafe[I]
    
    	NEXT I
    You're writing the values to EEPROM before you get the value from the array. I think it should look more like this.
    Code:
    '******************************************
    'Sauvegarde en EEPROM
    '******************************************
    
    	WRITE 0, mode
    
    	FOR I = 1 TO 4
    
    	Echantillon	= Voiesafe[I]    ' Get value first
    	WRITE I+1, Echantillon.Lowbyte
    	WRITE I,   Echantillon.Highbyte
    
    	NEXT I
    But then, it could just be my lack of understanding french.

    Best regards,
       Darrel

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Thumbs up

    Hi, Darrel

    Thanks for the comments, They have been already corrected, and few new lines added !!!

    one more bug ( ! ) is that I should have Written

    Echantillon = Voiesafe[I]
    WRITE 2*I-1, echantillon.lowbyte
    WRITE 2*I, echantillon.highbyte

    to get right values in the right place

    If you want me to fully translate it ...I will !

    Have a nice day

    Alain

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Simple Array Demo
    By Archangel in forum Code Examples
    Replies: 5
    Last Post: - 15th February 2010, 04:46
  3. Serial EEPROM
    By William in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 10th July 2009, 18:09
  4. Advanced Arrays
    By GoldStar in forum General
    Replies: 2
    Last Post: - 16th May 2009, 06:58
  5. Beginner trying to use arrays
    By captain in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 3rd November 2007, 07:20

Members who have read this thread : 2

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