PDA

View Full Version : Loading EEPROM



Dick Ivers
- 23rd August 2005, 03:25
How to enter the initial starting value into eeprom for a word
variable?

For example, suppose the variable is:

VITtime var word

it will be read from eeprom in 2 bytes, say:
read 0, VITtime.byte0
read 1, VITtime.byte1

Suppose I want the initially programmed numerical value in eeprom to be 365 (a word size number)
I usually use the EEPROM statement to enter initial numbers. Should it be:

EEPROM [5,36,....... .....]
or
EEPROM [65,3,.............]
or
EEPROM [365,.............]

or what?

CocaColaKid
- 23rd August 2005, 04:00
To load 365 in an eeprom location at programming time it would be:



data 109, 1


or



data %1101101,%1


This comes from breaking down the bits in the bytes of the word variable

decimal 365 = 0000 0001 0110 1101 binary

Since there are 8 bits to a byte, we now know that byte0 is 0110 1101b and byte1 is 0000 0001b. Convert these to decimal and you get 109 and 1 respectively. Both commands will accomplish the same thing.

You can also use:



write address, variable.Byte1
write address, variable.Byte0

and


read address, variable.Byte1
read address, variable.Byte0


This way can be done anywhere in the program. The DATA command is used to pre-load the eeprom location at time of programming.

Darrel Taylor
- 23rd August 2005, 04:44
OR, if you didn't feel like breaking down every word sized number manualy, you can let the compiler help you out.
Days CON 365
Dogs CON 1024
Mice CON 10000

EEPROM [Days&$FF, Days>>8, Dogs&$FF, Dogs>>8, Mice&$FF, Mice>>8]
Which would load ...

109, 1, 0, 4, 16, 39

It may seem a little awkward, but it's easier to make changes later on.

<br>

Dick Ivers
- 23rd August 2005, 12:47
Thanks guys .... it works.

Darrel Taylor
- 24th August 2005, 06:10
And, I completely forgot about the WORD modifier for the DATA statement.

DATA WORD 365

This would also store it as ...

109, 1

<br>
I hope Bruce and Melanie weren't watching :o

CocaColaKid
- 24th August 2005, 12:32
Now that is something I didn't know! Man that really makes things a lot easier. I'll have to try that when I get back in to office.

mister_e
- 25th August 2005, 03:44
I hope Bruce and Melanie weren't watching :o
I'm not one of the above but... i saw you :)

KISS programming, is the best way. We often forget the base of it.