Thursday, May 7, 2009

Memory? What memory?

Well, I know the memory is there, but how to get to it is the trouble. It is confusing for several reasons to me. First of all; there is more than one way to do it, but how and why they differ is not very well explained anywhere. First some general info from Microchip's PIC16F690 Data Sheet:

Data Memory is held in file registers. Instructions referring to file registers use 7 bits, so only 128 file registers can be addressed. Multiple file registers are arranged into “pages”. Two extra bits RP0 and RP1 (in the Status register) allow accessing multiple pages. These two bits effectively become the top two bits of the file register address. The additional pages may or may not be implemented, depending on the device.


So, this is the reason as to why we need to think about it at all, and then there is the means of how to do it. Again, from Microchip's, this time the "Low Pin Count Demo Board USer's Guide":


EXAMPLE 2-1: DEFINING DATA MEMORY


#define Length 0x20 ;c-like syntax

Length equ 0x20 ;equate 0x20 with the symbol

cblock 0x20 ;start a block of variables
Length ;this will be at address 0x20
Width ;this will be at address 0x21
Area:2 ;this is 2 bytes long, starting at address 0x22
Girth ;this will be at address 0x24
endc




So, here we can see three different ways of assigning variables to memory. But, there are other ways too. Here is an example from a template made by Microchip:


TEMP_VAR UDATA
temp RES 1 ;example variable definition

... and:


TEMP_VARS UDATA_SHR
temp1 RES 1
temp2 RES 1


... where the difference is that UDATA_SHR stands for shared, which is all good, but nowhere can I find what that means in terms of being different from just straight UDATA, or any of the other options. Maybe this is unimportant altogether, but I feel like this is maybe the least well explained topic when it comes to basic PIC programming. Hopefully I will get the picture later.

No comments:

Post a Comment