PDA

View Full Version : data with wordvar?



Pedro Santos
- 17th January 2007, 17:32
Hello

Can the DATA command handle word variable?
like this

Data @1, $1DF4, $FAFD, $AB13, $3FC3

For i = 1 to 4
read i,wordvar
'do anything
next i

Is this correct?

Thanks
Best Regards
Pedro

skimask
- 17th January 2007, 17:41
Hello

Can the DATA command handle word variable?
like this

Data @1, $1DF4, $FAFD, $AB13, $3FC3

For i = 1 to 4
read i,wordvar
'do anything
next i

Is this correct?

Thanks
Best Regards
Pedro

Data @0, $1DF4, $FAFD, $AB13, $3FC3

For i = 0 to 3
read i , wordvar.lowbyte
read i , workvar.highbyte
'do anything
next i

1st time thru wordvar = $1DF4
2nd time thru wordvar = $FAFD
3rd time thru wordvar = $AB13
4th time thru wordvar = $3FC3

It's all right there in your handy PicBasicPro manual that you got when you bought PicBasicPro, page 53 and page 123.
Mine's green, what color is yours?

Darrel Taylor
- 17th January 2007, 20:38
Mine's green, what color is yours?

Mine's Olive.

And yup, right there on page 53 is all about the DATA statement.

And in it, it says ...
"Only the least significant byte of numeric values are stored unless the WORD modifier is used"

Therefore:

Data @1, WORD $1DF4, WORD $FAFD, WORD $AB13, WORD $3FC3

Regards,

Pedro Santos
- 17th January 2007, 21:47
Hello Darrel

data @1, word $E276, word $E183, word $8001, word $EF90

and how can i read the variavle?

so?

for i = 1 to 4
read i, wordvar
''do anything
next i

is that correct?

Thanks

Regards

Pedro

skimask
- 17th January 2007, 22:54
Hello Darrel

data @1, word $E276, word $E183, word $8001, word $EF90

and how can i read the variavle?

so?

for i = 1 to 4
read i, wordvar
''do anything
next i

is that correct?

Thanks

Regards

Pedro

Did you even see post #2 above?

Darrel Taylor
- 17th January 2007, 22:56
Well, like everthing else, there's probably 100 different ways to go about it. And the best way depends on how your program needs to use it.

But the biggest thing to remember is that you can only READ 1 byte at a time. So, to read a WORD value must be done in 2 operations.

READ 1, wordvar.LowByte
READ 2, wordvar.HighByte

If you wanted to read the data into an array of WORDS, you could do this...

ArraySize CON 4
WordArray VAR WORD[ArraySize]
Ptr VAR BYTE
DataStart VAR BYTE

DataStart = 1
For Ptr = 0 to (ArraySize * 2) -1
READ DataStart + Ptr, WordArray.LowByte(Ptr)
Next Ptr

If you just want to read individual words, then you'll need to know where they are located in EEPROM. You could just count bytes in the data and use the starting address as the location for the READ. But as the program changes, the data might change too, and all those locations you counted fly out the window.

So the easiest way to deal with individual Locations is to give them names in the DATA statement. Then when things change, the pointers to the data change too.


Calibration DATA @1, WORD $1DF4
Offset DATA WORD $FAFD
Something DATA WORD $AB13
Another DATA WORD $3FC3

READ Something, wordvar.LowByte
READ Something + 1, wordvar.HighByte

; returns $AB13

READ Calibration, wordvar.LowByte
READ Calibration + 1, wordvar.HighByte

; returns $1DF4

Well, that's 3 possibles, at least 97 more available. :)

HTH,

Pedro Santos
- 17th January 2007, 23:26
Thank's Darrel for your help

Regards

Pedro

Darrel Taylor
- 17th January 2007, 23:28
Oh Yeah, forgot to mention that you might find this usefull as well.

EEPROM Variables (EE_Vars.pbp)
http://www.picbasic.co.uk/forum/showthread.php?t=2444
<br>

skimask
- 17th January 2007, 23:43
Oh Yeah, forgot to mention that you might find this usefull as well.

EEPROM Variables (EE_Vars.pbp)
http://www.picbasic.co.uk/forum/showthread.php?t=2444
<br>

And man oh man, did I screw up my example above in post #2... :D If you'll excuse me for a moment, I'm going to go outside and kick my own a$$...

Darrel Taylor
- 18th January 2007, 00:14
Could you get someone to take a picture of that?

Just thought it might Brighten somebody's Day. :D
<br>

skimask
- 18th January 2007, 00:35
Could you get someone to take a picture of that?

Just thought it might Brighten somebody's Day. :D
<br>

I think I'm allowed that one. Maybe not.
How's this one for ya? :)

And besides, I get to drive from here to Tucson tomorrow morning... 58 miles from Canada to 58 miles from Mexico, one end of the country to the other.