I'm sure I'm missing something...
I'm new to micro controllers...
I'm using a zx-24p. I'm wanting to write an array and some variables to program (persistent) memory but I'm not sure what address to use. How do I know I'm not going to step on the program area? I've looked at the Ref & Lib manuals but am missing something in my understanding.
PutEEPROM(), PutPersistent() & PutProgMem() all talk about a starting address but I'm lost because I've always used variable names in RAM and never had to think about actual memory addresses.
Any help on were to start?
I'd like to see an app. note or something on writing variables and arrays to persistent memory and getting them back again.
Thanks
Ed Kelly
Writing an Array to Program Memory???
Re: Writing an Array to Program Memory???
Before addressing the specifics, it is important to understand that Persistent Memory and Program Memory are different memory areas and they have different characteristics. Unlike RAM, both Persistent Memory and Program Memory have write cycle limits. When you exceed the stated number of writes, data retention may become unreliable.edkelly wrote:I'm wanting to write an array and some variables to program (persistent) memory [...].
Persistent Memory is implemented using the internal EEPROM on the CPU chip. Persistent Memory is divided into two regions: the system area and the user area. The system area is the first 32 or 64 bytes of Persistent Memory (beginning at address zero). The user area begins at address 32 or 64 and, depending on the ZX device, contains between 996 bytes and 4064 bytes. The write cycle limit of Persistent Memory is 100,000 writes.
Program Memory is the memory area where your program's code is stored along with Program Memory data items defined by your program. Depending on the ZX model, Program Memory is implemented either in the CPU chip's internal Flash Memory (ZX-1281, ZX-1280, all native mode devices) or in an external serial EEPROM (all VM mode devices except the ZX-1281 and ZX-1280). Program Memory begins at address zero and the size varies from 32K (ZX-24a, ZX-24p) up to 124K (ZX-1281n, ZX-1280n). The write cycle limit for external EEPROM Program Memory is 1,000,000 cycles and it is 10,000 for internal Flash Program Memory.
Whether using Persistent Memory or Program Memory for data storage, you have two choices with regard to address allocation. The simplest method is to define a variable in the desired memory space and let the compiler assign the address. The more complicated alternative is to use the left over (unassigned) space and manage the address allocation yourself.
If you define the Persistent Memory or Program Memory variables, the compiler will automatically assign an address to the defined variable and you can read/write it the same way that you do RAM-based variables (with the exception that you can't pass them by reference to a subroutine/function). Here is a code snippet that defines both a Persistent Memory variable and a Program Memory variable.
Code: Select all
Dim myPersVar as Persistent Integer
Dim myProgVar as ProgMem Single
myPersVar = 23
myProgVar = 6.02e23
Debug.Print Fmt(myProgVar, 2)
Debug.Print myPersVar
If you need the address of either of these types of variables (or any variable, for that matter) you can use the DataAddress property.
Code: Select all
addr = myProgVar.DataAddress
If you decide to manage the address assignment yourself and use GetPersistent()/PutPersistent() or GetProgMem()/PutProgMem() to read/write it, you can use the space beyond that which is automatically assigned by the compiler. To do so, you need to know the address of the first available byte. The code snippet below shows how to get these addresses.
Code: Select all
Dim persAddr as UnsignedInteger
persAddr = Register.PersistentStart + Register.PersistentUsed
Debug.Print "persAddr = ";persAddr
Dim progAddr as Long
progAddr = Register.CodeSize
Debug.Print "progAddr = ";progAddr
- Don Kinzer