Quote Originally Posted by brittons View Post
Thanks, Darrel. I really like your program and am starting to experiment with it. The way I was working with EEProm Vars was quite the convoluted mess with the same problems you mentioned in your EE_Vars documentation. Hopefully this will make life easier.
You are very welcome, and I hope it helps you too.

> So from what I understand if I just set the value in EE_start to zero everything gets reinitialized when I reset the pic.

Correct!

> Does the compiler insert the macro code for each variable? Is there a lable created by the macro to find the default values for each variable? I'm just trying to understand how this works a little better.

Yes it does, and this will probably add more confusion instead of answering the question, but since you want to learn, here goes.<hr>

When you create an EE_var, several of it's properties are stored as Constants in the assembler.
For this variable ...

MyVar VAR WORD : @ EE_var _MyVar, WORD, 1000

Between the EE_var and EE_assign macros, it will create the following constants.

Code:
EE_Var1_Default     = 1000    ; the Default value
EE_Var1_PTR         = 1       ; the address of the data in EEPROM
EE_Var1_Size        = 2       ; size of the variable
EE_Var1_HasVariable = 1       ; 1 if Linked to a PBP variable
EE_Var1_Variable    = 60      ; Address to the PBP variable that's linked
EE_VarLink60        = 1       ;  and a way to find the "link" from the variable
If you create a second EE_var ...

SecondVar VAR BYTE : @ EE_var _SecondVar, BYTE, 75

it would create these constants ...
Code:
EE_Var2_Default     = 75      ; the Default value
EE_Var2_PTR         = 3       ; the address of the data in EEPROM
EE_Var2_Size        = 1       ; size of the variable
EE_Var2_HasVariable = 1       ; 1 if Linked to a PBP variable
EE_Var2_Variable    = 62      ; Address to the PBP variable that's linked
EE_VarLink62        = 2       ;  and a way to find the "link" from the variable
At this point, they're all just a bunch of constants. They don't do anything, and they haven't used any code space. But you can see them in the "Symbol Table" at the bottom of the .lst file.

And in an odd sort of way, it becomes a "database" of information that you can query for the desired results.

For instance, if I know the variable name (SecondVar), and I want to know which EEPROM variable has been "linked" to it?
Using the same Text Substitution that the macro's use ....

TheEEvar = EE_VarLink#v(_SecondVar)

The #v(_SecondVar) part is the "Text Substitution". It will be replaced with the value inside the brackets. In this case it's the address of the variable which was 62.

So it turns into ...

TheEEvar = EE_VarLink62

Which returns 2. The second EE_var that was linked to a PBP variable.

Now that you know which EE_var was linked to it, you can use that value to query the other parameters.

<pre>EE_Default = EE_Var#v(TheEEvar)_Default<br>EE_Loc = EE_Var#v(TheEEvar)_PTR<br>EE_Size = EE_var#v(TheEEvar)_Size</pre>This pulls up all the pertinent data about that EE_var. Which is what the GetEEinfo macro does.

If you want to use those constants in PBP, all you need to do is declare a CON EXT for each one.
Code:
EE_Default  CON EXT
EE_Loc      CON EXT
EE_Size     CON EXT
And walla, a variable database, with zero code space. <hr>
If none of this makes any sense, don't worry. I write this stuff for everyone. Someday, someone will slap themself on the forehead and go. "That's It!". And if not now, six months from now might result in the same slap. Which of course, makes me "Slap Happy".


> I have a case where I may want to loop through a group if variables and save them to EEProm, is there a way to do this using EE_Vars.

Well, EE_vars wasn't set up for persistent Arrays. It's not that it can't be done. I just didn't do it.

> Can you recommend any reading to better familiarize myself with macros?

I'll say the same thing I always say ...
If you want to learn Macro's, you already have the best "Interactive" tutorial there is ... PBP.

For all the things you can do with PBP, you can create a 1-line program. More when you get better at it. That answers the specific question you may have. Like, "how do I set a port to Output?

Just create a small program that has 1 line ...

OUTPUT PORTB.0

After you compile it, you'll find a .ASM .MAC and .LST file in the folder that the original program was in.
Start with the .ASM

Those files will give you more insight into the workings of macro's, than ANY book I've ever seen.

Really, no I'm serious. Try it!
You can ask it any question (that PBP can do), and you'll get an answer that relates to your question, instead of an example to some project that the book was based on.