Loading symbols with data from the EEPROM

ciseco

Senior Member
Hi,

I've just tried to define two symbols by reading the contents of the eeprom but it's I guess associating the variable with the symbol not it's actual contents. My program crashes with this (b1 gets used as a variable elsewhere, which is why it crashes, the below statement works fine if I dont ever use b1 again)

eeprom 0,("##")
read 0,b1
symbol s1=b1
read 1,b1
symbol s2=b1


But it's fine if I do this

symbol s1="#"
symbol s2="#"

do I have to do something akin to (not that this works) or can't it be done?

read 0,b1
symbol s1=val(b1)
read 1,b1
symbol s2=val(b1)


Cheers

Miles
________
Yamaha YZ250F history
 
Last edited:

Technical

Technical Support
Staff member
Symbols are only used on the computer before compilation, not in the chip. They are just alternate 'labels' for constants or variables.

s1 is not a variable location, which is what in effect you are trying to do in program 2. You can't have two separate variables s1and b1!

So use

symbol s1 = b1
symbol s2 = b2
eeprom 0,("**")

read 0,s1
read 0,s2
 

BeanieBots

Moderator
"Symbol" can't be used that way.
It's used to define a new name for a variable or constant value.
You define it as a directive for the compiler, not as a command.
eg
symbol MyVar = b0
or
symbol Red_LED = 7

From that point on in your code, you can use "Red_LED" and "MyVar" instead of "b0" and "7".

What exactly is it that you are trying to do?
 

ciseco

Senior Member
Ah, law of sod, I suspected as much.

What I want to do is not make s1 & s2 dependant on any variable as I use them all in code, just set their static value at power up from two bytes in the EEPROM.

I guess the only work around is to load them

read 0,b1
read 1,b2

at any time I need them and remember that I can't use them for anything else until disposed of, this was the very reason I defined them as symbols to start with to avoid having to dump stuff in scratchpad, re use variables then reload what I didn't have space for.

By using

symbol s1="#"
symbol s2="#"

I'm not tying up a variable (or am I, and I just dont realise)

Is there anyway to re-poke a value onto a constant?

It's so that the sensor device can have it's ID (2 bytes) changed on the fly and remember it's settings during a power cycle. In essence all devices power up with ## which means "I'm new" then it'll be changed to somthing more meaningful like K2 (sensor 2 in the kitchen for example). This also means I can write a little routine at the front so if a reset buton is pressed at power up, the sensor defaults to it's original settings if something gets screwed up. The EEPROM stores various things like device name, firmware revision, PANID, channel, encyrption key etc. All things that only need changing once in a blue moon. These two bytes are the only things that need to be constants, as they get used all the time in code.

Have I confused things even further :)

Miles
________
Mercedes-Benz W125 specifications
 
Last edited:

Technical

Technical Support
Staff member
You need to understand constants and variables. Constants cannot, ever, be changed as the program is running. Hence their name!

You are talking about variables - two bytes that can change their value from '*' to something else. They have to be variables.
 

ciseco

Senior Member
Hi,

I understand, I didn't want to change them whilst running. I wanted a way of changing them pre power up. If it's not possible except for at download time it's not possible, cheers for clarifying.

Miles
________
Toyota W transmission specifications
 
Last edited:
Top