How to define constants that specify eeprom addresses


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2009
    Location
    Edmonton AB Canada
    Posts
    5

    Default How to define constants that specify eeprom addresses

    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

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Skip the EEPROM statement, and use DATA.

    If you know the last used EEPROM location from the previous program.
    Start somewhere after that with ...
    Code:
    DATA @128 ; anywhere past the original data
    Then let PBP decide where the rest goes with ...
    Code:
    ee_patnum      DATA 2
    ee_stepnum     DATA 0
    ee_bright      DATA 255
    ee_xfade       DATA 254
    And when you want to retrieve it ...
    Code:
    READ ee_bright, bright
    READ ee_xfade, xfade
    Or write to it ...
    Code:
    WRITE ee_bright, bright
    WRITE ee_xfade, xfade

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

    hth,
    DT

  3. #3
    Join Date
    Dec 2009
    Location
    Edmonton AB Canada
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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 ...
    Code:
    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. ...
    DT

  5. #5
    Join Date
    Dec 2009
    Location
    Edmonton AB Canada
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. RF Modules
    By tonyfelloni in forum mel PIC BASIC Pro
    Replies: 44
    Last Post: - 26th June 2010, 17:42
  2. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 14:46
  3. RX TX modules - intermitent communication
    By ruijc in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 11th June 2009, 00:13
  4. Data EEPROM gets clobbered during programming
    By BrianT in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th July 2008, 02:46
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 19:59

Members who have read this thread : 2

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts