PDA

View Full Version : How to define constants that specify eeprom addresses



DwayneR
- 8th December 2009, 01:17
Good day to all.

I am a relative PICbasic Pro newbie but have several years of writing PIC assembler code.

I am taking some older PICbasic Pro code written by a co-worker and making some simple changes. Some of those changes require moving to a larger PIC.

The current PIC has 128 bytes of eeprom. The PIC I'm moving to has 256 bytes of eeprom.

User data in the eeprom is stored beginning at address 0. System data is stored in the eeprom starting at the top and growing downward.

I'm trying to use symbolic names for the upper eeprom addresses but failing miserably. I'm hoping that someone can point me in the right direction.

Here's what I've tried so far:

'eeprom aliases
ee_max con 255 'highest eeprom address
ee_patnum con (ee_max) 'eeprom addr for number of current pattern
ee_stepnum con (ee_max-1) 'eeprom addr for current step number in pattern
ee_bright con (ee_max-2) 'ee addr for stored brightness
ee_xfade con (ee_max-3)
ee_maxpot con (ee_max-4) ' ee addr for max pot (not currently used)

eeprom ee_patnum, [2] 'current pattern
eeprom ee_stepnum, [0] 'which step within pattern we are on
eeprom ee_bright, [255] 'brightness
eeprom ee_xfade, [254] 'crossfade point

The first chunk of instructions is intended to allow easy changing of eeprom size. The idea is that I simply specify the highest eeprom address and the remaining addresses are calculated automatically.

But: it doesn't work. I get a Syntax error.

I can do this in assembler easily. I'm hoping there is a similarly easy method of doing this in PICbasic Pro.

Many thanks!

dwayne

Darrel Taylor
- 8th December 2009, 01:51
Skip the EEPROM statement, and use DATA.

If you know the last used EEPROM location from the previous program.
Start somewhere after that with ...

DATA @128 ; anywhere past the original data
Then let PBP decide where the rest goes with ...

ee_patnum DATA 2
ee_stepnum DATA 0
ee_bright DATA 255
ee_xfade DATA 254

And when you want to retrieve it ...

READ ee_bright, bright
READ ee_xfade, xfade

Or write to it ...

WRITE ee_bright, bright
WRITE ee_xfade, xfade


If you have PBP 2.60, you can also have DATA Words or Longs.

hth,

DwayneR
- 8th December 2009, 03:22
Thanks, Darrel.

The main reason that I'm trying to do this symbolically is that the size (amount) of the user data changes. I simply want to maximize the amount of user space available, without having to re-calculate the system addresses when I change PICs.

Its a lot easier if I can just tell the compiler what the last address is and have it assign system variables automatically, starting from the top and working downwards.

Part of this learning exercise is developing the techniques I will be using in the future.

Your example helps a lot - I see how to assign symbol names to specific addresses. That makes it easy to re-write the code to avoid using hard-coded numeric constants as is done currently.

What I'd like to do now is have the addresses assigned automatically, if that is possible.

Any ideas?

Many thanks!

dwayne

Darrel Taylor
- 8th December 2009, 03:43
EEPROM allocation only increments.

And whether you're counting from end up or top down, you still need to know where the original program's highest EEPROM location is, and how many bytes you need now.

Going from end-up will make it longer before you overwrite locations, but it won't keep you from doing it.
If you start from the end of previous eeprom usage and add more as needed, then the compiler will let you know when you've run out.

But anyhow, if you know how many bytes you are adding(EEusedNow), and you know how many bytes are available ...

MaxEEPROM CON 255
EEusedNow CON 65

DATA @MaxEEPROM - EEusedNow + 1

ee_patnum DATA 2
ee_stepnum DATA 0
ee_bright DATA 255
ee_xfade DATA 254

;... etc. ...

DwayneR
- 8th December 2009, 04:07
I think that will work quite nicely.

I know how many system variables that I have (not many) and I will certainly keep track of the user variables.

This does exactly what I want: provides me with a single place where I can specify the eeprom size.

Many thanks!

dwayne