PDA

View Full Version : word arrays and eeprom



Acetronics2
- 7th January 2005, 17:57
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

Darrel Taylor
- 8th January 2005, 01:57
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

Acetronics2
- 8th January 2005, 09:34
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

Darrel Taylor
- 8th January 2005, 19:38
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.
'******************************************
'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.
'******************************************
'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

Acetronics2
- 9th January 2005, 07:36
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