writing word variables to data memory


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    This seems to compile

    Code:
      for fn = 0 to 3
      write (10*fn + 80),lightsetHR[fn]
      write (10*fn + 82),lightsetMN[fn]
      write (10*fn + 84),lightoffHR[fn]
      write (10*fn + 86),lightoffMN[fn]
      write (10*fn + 88),word droptemp[fn]
      write (10*fn + 90),word normtemp[fn]
      write (10*fn + 92),StartHour[fn]
      write (10*fn + 94),StartMin[fn]
      write (10*fn + 96),StopHour[fn]
      write (10*fn + 98),StopMin[fn]
      write (10*fn + 100),word alarmhigh[fn]
      Write (10*fn + 102),word alarmlow[fn]
      next fn

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    This seems to compile

    Code:
      for fn = 0 to 3
      write (10*fn + 80),lightsetHR[fn]
      write (10*fn + 82),lightsetMN[fn]
      write (10*fn + 84),lightoffHR[fn]
      write (10*fn + 86),lightoffMN[fn]
      write (10*fn + 88),word droptemp[fn]
      write (10*fn + 90),word normtemp[fn]
      write (10*fn + 92),StartHour[fn]
      write (10*fn + 94),StartMin[fn]
      write (10*fn + 96),StopHour[fn]
      write (10*fn + 98),StopMin[fn]
      write (10*fn + 100),word alarmhigh[fn]
      Write (10*fn + 102),word alarmlow[fn]
      next fn
    Malc,

    Yes, It compiles BUT:

    IF fn = 1 ...

    @ location 110 & 111 you write AlarmHigh[1]

    IF fn = 2

    location 110 & 111 are overwritten by NormTemp[2]

    IF fn = 3

    location 110 is overwritten by lighsetHR[3]

    and I only give you 3 examples ...

    so, ... try

    Code:
     
     write  80,lightsetHR[1]),lightsetMN[1],lightoffHR[1],lightoffMN[1],word droptemp[1] ,word normtemp[1],StartMin[1],StopHour[1],StopMin[1],word alarmhigh[1],StartHour[1],word alarmlow[1] ; need 16 locations
     
     write  100,lightsetHR[2]),lightsetMN[2],lightoffHR[2],lightoffMN[2],word droptemp[2] ,word normtemp[2],StartMin[2],StopHour[2],StopMin[2],word alarmhigh[2],StartHour[2],word alarmlow[2]
     
     write  120,lightsetHR[3]),lightsetMN[3],lightoffHR[3],lightoffMN[3],word droptemp[3] ,word normtemp[3],StartMin[3],StopHour[3],StopMin[3],word alarmhigh[3],StartHour[3],word alarmlow[3]
     
     
     write  140,lightsetHR[4]),lightsetMN[4],lightoffHR[4],lightoffMN[4],word droptemp[4] ,word normtemp[4],StartMin[4],StopHour[4],StopMin[4],word alarmhigh[4],StartHour[4],word alarmlow[4]
    This Way, your EEPROM Map is neat ... and you know where to find What ...
    ...

    What did you tell me by PM ???

    I just call that pedagogics ...

    Alain
    Last edited by Acetronics2; - 5th August 2010 at 22:09.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Alain,

    Many thanks......

    Apologies for the PM - just having a bad day.

    I'll give that a try in the morning

  4. #4
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    This seems to compile

    Code:
      for fn = 0 to 3
      write (10*fn + 80),lightsetHR[fn]
      write (10*fn + 82),lightsetMN[fn]
      write (10*fn + 84),lightoffHR[fn]
      write (10*fn + 86),lightoffMN[fn]
      write (10*fn + 88),word droptemp[fn]
      write (10*fn + 90),word normtemp[fn]
      write (10*fn + 92),StartHour[fn]
      write (10*fn + 94),StartMin[fn]
      write (10*fn + 96),StopHour[fn]
      write (10*fn + 98),StopMin[fn]
      write (10*fn + 100),word alarmhigh[fn]
      Write (10*fn + 102),word alarmlow[fn]
      next fn
    Malcolm,

    This code won't work anymore like Alain already mentioned. Now, you have words instead of bytes. Also, now you have 12 variables instead of 10 .

    Now, if you try to write 12*2*4=96 bytes at location 80 then you are going to overwrite all the stuff that you wrote at location 150 with your DATA command (from your other post).

    I would suggest that you should try first to clear up the mess by organizing the data that you put in EEPROM. It looks like the amount of data that you are putting in memory by doing "Data @0,0 and Data @150" is 58 bytes for each DATA command. So, instead of "Data @0,0 and Data @150" try something like "Data @0,0 and Data @58". Then from location 116 and up you have no data that could get overwritten.

    Next, try the same code as above but with the following changes.

    Code:
    for fn = 0 to 3
      write (12*fn + 116),lightsetHR[fn]
      write (12*fn + 118),lightsetMN[fn]
      write (12*fn + 120),lightoffHR[fn]
      write (12*fn + 122),lightoffMN[fn]
      write (12*fn + 124),word droptemp[fn]
      write (12*fn + 126),word normtemp[fn]
      write (12*fn + 128),StartHour[fn]
      write (12*fn + 130),StartMin[fn]
      write (12*fn + 132),StopHour[fn]
      write (12*fn + 134),StopMin[fn]
      write (12*fn + 136),word alarmhigh[fn]
      write (12*fn + 138),word alarmlow[fn]
    next fn
    I replaced 10 by 12 since now you have 12 variables. I hope that this helps.

    Robert
    Last edited by rsocor01; - 6th August 2010 at 01:23.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  5. #5
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default Thanks

    Robert, thanks for the input, and yes I agree that it needs tidying up. I've already moved Alain's code down by 10 (ie first line starts at 70, the second 90 etc as I thought that I might be getting close to over-writing data at the 150 location.

    Guys, I appreciate the time and trouble you have gone to... sorry that it seemed an uphill struggle - it must be the medication I'm on (that's my story and I'm sticking to it )

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Lightbulb

    Quote Originally Posted by malc-c View Post
    I've already moved Alain's code down by 10 (ie first line starts at 70, the second 90 etc as I thought that I might be getting close to over-writing data at the 150 location.
    Hi, Malc you also can optimize memory use a bit not to hit location 150 ... see: 80 = $ 50 ... as you need 16 locations per fn value ... locations $50 ...$5F for fn = 1 ............ $60 ...$6F for fn = 2 ... ... .............$80 ... $8F for fn = 4 ... $8F = 143 ... it makes it !!! so, simply change locations to:
    Code:
    write  $50,lightsetHR[1]),lightsetMN[1],lightoffHR[1],lightoffMN[1],word droptemp[1] ,word normtemp[1],StartMin[1],StopHour[1],StopMin[1],word alarmhigh[1],StartHour[1],word alarmlow[1] ; need 16 locations
     
     write  $60,lightsetHR[2]),lightsetMN[2],lightoffHR[2],lightoffMN[2],word droptemp[2] ,word normtemp[2],StartMin[2],StopHour[2],StopMin[2],word alarmhigh[2],StartHour[2],word alarmlow[2]
     
     write  $70,lightsetHR[3]),lightsetMN[3],lightoffHR[3],lightoffMN[3],word droptemp[3] ,word normtemp[3],StartMin[3],StopHour[3],StopMin[3],word alarmhigh[3],StartHour[3],word alarmlow[3]
     
     write  $80,lightsetHR[4]),lightsetMN[4],lightoffHR[4],lightoffMN[4],word droptemp[4] ,word normtemp[4],StartMin[4],StopHour[4],StopMin[4],word alarmhigh[4],StartHour[4],word alarmlow[4]
    and moreover, you'll see your values nicely ordered into your EEPROM Watch Window ... Have a nice day Alain PS: sorry , but there's a forum bug with " carriage return ", it seems ...
    Last edited by Acetronics2; - 6th August 2010 at 13:24.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Members who have read this thread : 0

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

Posting Permissions

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