Data memory - explanation please


Closed Thread
Results 1 to 10 of 10
  1. #1
    malc-c's Avatar
    malc-c Guest

    Default Data memory - explanation please

    Hi,

    I have two sets of data stored in the PIC -
    Data @0,0 and Data @150

    I want to save 10 arrays each with 4 values ( eg tempset(1), tempset(2), etc) to the PICs memory, which can then be read back on power up, but I'm not sure at what location I should save them to as the data table is in hex



    Could someone explain, or come up with a revision of the memory map to make better use of it ?

    Thanks

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I'm convinced that I am missing something, but why can't you just save them as follows:

    For X = 0 to 3
    Write X,Array1[X]
    Next X

    For X = 4 to 7
    Write X,Array2[X-4]
    NextX

    ...
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    Hi Charles,

    Sorry, please bear with me as this is the first time I've experimented with saving data other than when programming mode.

    I want to save the following to the PIC once the user has set them so that in the event of a power failure they are remembered and the user doesn't have to re-enter the data.

    Code:
    save:
    Lcdout $FE,2
    LCDOUT $FE,$80,"Saving Settings"
    for fn= 0 to 3
    write ,lightsetHR[fn]
    write ,lightsetMN[fn]
    write ,lightoffHR[fn]
    write ,lightoffMN[fn]
    write ,droptemp[fn]
    write ,normtemp[fn]
    write ,StartHour[fn]
    write ,StartMin[fn]
    write ,StopHour[fn]
    write ,StopMin[fn]
    next fn
    pause 150
    goto mainmenu
    However as the program writes data to the memory at the time of programming and as part of the RTC settings (data@ 0,0 and data@150 respectively) I'm not sure what value to place before the colon after the word statement for each of the above. I don't want to corrupt the data stored at those data locations.

    For example - 0x50 address in that table appears blank (FF) - so could I use
    Code:
    write 0x50 ,lightsetHR[fn]
    Or whatever decimal 0x50 would be ???

    Hope that's clear ?

    Oh and I'm using DT's interrupts... would I need to use DEFINE WRITE_INT 1 withing that sub-routine ?
    Last edited by malc-c; - 1st August 2010 at 18:40. Reason: had an additional thought !

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


    Did you find this post helpful? Yes | No

    Default

    Yes, you can use 0x50 if you want to. There is nothing written there. Since 0x50h = 80 you can use something like this

    Code:
    for fn= 0 to 3
      write (10*fn + 80),lightsetHR[fn]
      write (10*fn + 81),lightsetMN[fn]
      write (10*fn + 82),lightoffHR[fn]
      write (10*fn + 83),lightoffMN[fn]
      write (10*fn + 84),droptemp[fn]
      write (10*fn + 85),normtemp[fn]
      write (10*fn + 86),StartHour[fn]
      write (10*fn + 87),StartMin[fn]
      write (10*fn + 88),StopHour[fn]
      write (10*fn + 89),StopMin[fn]
    next fn
    I haven't tested this code so I don't know if the (10*fn + 8x) works in the WRITE command. If it doesn't then try something like this

    Code:
    for fn= 0 to 3
      Mem_address = (10*fn) + 80
      write Mem_Address,lightsetHR[fn]
      Mem_address = (10*fn) + 81
      write Mem_address,lightsetMN[fn]
      Mem_address = (10*fn) + 82
      write Mem_address,lightoffHR[fn]
      Mem_address = (10*fn) + 83
      write Mem_address,lightoffMN[fn]
      Mem_address = (10*fn) + 84
      write Mem_address,droptemp[fn]
      Mem_address = (10*fn) + 85
      write Mem_address,normtemp[fn]
      Mem_address = (10*fn) + 86
      write Mem_address,StartHour[fn]
      Mem_address = (10*fn) + 87
      write Mem_address,StartMin[fn]
      Mem_address = (10*fn) + 88
      write Mem_address,StopHour[fn]
      Mem_address = (10*fn) + 89
      write Mem_address,StopMin[fn]
    next fn

    Quote Originally Posted by malc-c View Post
    Oh and I'm using DT's interrupts... would I need to use DEFINE WRITE_INT 1 withing that sub-routine ?
    You need to disable the interrupts for the WRITE command to work. I read somewhere in this forum that the WRITE_INT is only for WRITECODE, but you might want to try it.

    Robert
    "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

    Robert,

    Thanks for the assistance. I'll give it a try and no doubt will be back with some feedback

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


    Did you find this post helpful? Yes | No

    Default

    Robert,

    Thank you. The first version works a treat !

  7. #7
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    Robert,

    Thank you. The first version works a treat !
    Good to hear that .

    What program did you use in your first post to see the contents of the EEPROM memory? That seems to be very helpful. I could use it for my own projects.

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rsocor01 View Post
    Good to hear that .

    What program did you use in your first post to see the contents of the EEPROM memory? That seems to be very helpful. I could use it for my own projects.

    Robert
    I have an easyPIC5 development board and that is part of the software that squirts the HEX to the PIC - http://www.mikroe.com/eng/products/v...opment-system/

    Not sure if the PicFLASH2 software will work with other programmers, but it will work with one of their other products http://www.mikroe.com/eng/products/view/392/picflash2/

    The software is a free download

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


    Did you find this post helpful? Yes | No

    Default

    Uhmm maybe I spoke too soon...

    I have a menu section, which in tern selects sub menus to set the various variables up and then return back to the main menu. The last option of the main menu is this

    Code:
    LCDOUT $FE,1 
    Gosub SetButtonRelease
    Lcdout $FE,2
    LCDOUT $FE,$80,"Saving Settings"
    for fn= 0 to 3
      write (10*fn + 80),lightsetHR[fn]
      write (10*fn + 81),lightsetMN[fn]
      write (10*fn + 82),lightoffHR[fn]
      write (10*fn + 83),lightoffMN[fn]
      write (10*fn + 84),droptemp[fn]
      write (10*fn + 85),normtemp[fn]
      write (10*fn + 86),StartHour[fn]
      write (10*fn + 87),StartMin[fn]
      write (10*fn + 88),StopHour[fn]
      write (10*fn + 89),StopMin[fn]
      write (10*fn + 90),alarmhigh[fn]
      Write (10*fn + 91),alarmlow[fn]
      
    next fn
    pause 150
    goto main
    which when selected should write all the variables to memory before going to the main program.

    On powerup the values are read back in as part of the initialisation

    Code:
    for fn= 0 to 3
      read (10*fn + 80),lightsetHR[fn]
      Read (10*fn + 81),lightsetMN[fn]
      Read (10*fn + 82),lightoffHR[fn]
      Read (10*fn + 83),lightoffMN[fn]
      Read (10*fn + 84),droptemp[fn]
      Read (10*fn + 85),normtemp[fn]
      Read (10*fn + 86),StartHour[fn]
      Read (10*fn + 87),StartMin[fn]
      Read (10*fn + 88),StopHour[fn]
      Read (10*fn + 89),StopMin[fn]
      Read (10*fn + 90),alarmhigh[fn]
      Read (10*fn + 91),alarmlow[fn]
      
    next fn
    the strange thing is that the normaltemp, alarmhigh and alarmlow values don't appear to of been saved (or are being misread in some way).

    Interestingly, the data view doesn't show anything at 80
    Last edited by malc-c; - 4th August 2010 at 16:04. Reason: added image

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


    Did you find this post helpful? Yes | No

    Default

    I think I've discovered part of the problem, in that I'm using word rather than bytes.

    The manual states:
    To write a word, each of the 2 bytes that make up the word must be
    written separately:
    w Var Word
    WRITE 0,w.BYTE0
    WRITE 1,w.BYTE1
    I'm a little stumped as to how I need to write and read back a mixture of byte and word, the values which are words are typically represented as three digit numbers eg: 567 thus represents 56.7 degrees, so the alarmhigh(fn) will all be three digit numbers

Members who have read this thread : 1

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