PDA

View Full Version : Data memory - explanation please



malc-c
- 1st August 2010, 15:55
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

http://micro-heli.co.uk/dump.jpg

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

Thanks

Charles Linquis
- 1st August 2010, 17:19
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

...

malc-c
- 1st August 2010, 18:26
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.



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


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 ?

rsocor01
- 1st August 2010, 21:27
Yes, you can use 0x50 if you want to. There is nothing written there. Since 0x50h = 80 you can use something like this


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


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




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

malc-c
- 1st August 2010, 22:01
Robert,

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

malc-c
- 1st August 2010, 23:11
Robert,

Thank you. The first version works a treat !

rsocor01
- 2nd August 2010, 01:02
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

malc-c
- 2nd August 2010, 08:24
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/view/1/easypic5-development-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

malc-c
- 4th August 2010, 15:50
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



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



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
http://micro-heli.co.uk/data2.jpg

malc-c
- 4th August 2010, 18:06
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