PDA

View Full Version : Replacing an ARRAY with EEPROM write to save space?



Tom Gonser
- 12th March 2005, 14:24
Hi folks:

I have a couple big arrays in a program, and I am running out of codespace on the 16F88. I'd like to use EEPROM to store the data vs an array to free up some space, but am unsure of the approach to be taken. I've played with WRITE and READ, but not in a loop that did anything...

An example array is as follows:

1. The variables:
foo.array var byte[34] ' the array that will contain all the data
....

2. Program:

' get data - read from serial pin data that comes in every second

Serin2 Cpinin,84,1000,nodata,[wait($02,$47), STR foo.array\34]

' Calculate the variables from the array

' read data for temperature which is in hex
SSD4= (foo.array[24]>>4)
SSD3= (foo.array[24] & $f)
SSD2= (foo.array[23]>>4)
SSD1= (foo.array[23] & $f)

Dec_temp=(ssd4*4096)+(ssd3*256)+(ssd2*16)+ssd1 ' convert to decimal

...
...

' write out the new data to display

serout2 cpinout, 84,["Temp: ",Dec_temp]

'Loop back and read the next data from serial again..

Bruce
- 12th March 2005, 18:25
Arrays don't use program memory. They are created in RAM (shown as SRAM in your datasheet).

PBP system variables can require up to 24 bytes for the 16F family & 26 bytes for the 18F family. How many are actually used depends on the PBP command used in your program, the target device, and library routines included at compile time, etc...

Your array of 34 bytes + PBP max system vars is only 58 bytes. For the 16F88 you have 368 bytes - so you still have 310 bytes RAM left to play with.

You can store information in data EEPROM, or flash program memory, but you can't work with EEPROM like you can with "variables" in a RAM data array.

I.E. you can read data into your RAM array, then stash it in EEPROM, but you can't read your data directly into a string "STR foo.array\34" into EEPROM.

Tom Gonser
- 12th March 2005, 18:31
Thanks much! This is good to know!