This tutorial is about placing data in a specific ram(random access memory) location/address using xc8 compiler and mplabx ide. I am using microchip pic16f877 8-bit microcontroller in this tutorial. It has 8KB of rom (read access memory) and 368 Bytes of ram(random access memory). Its generally not recommended to place data in data memory(ram). Since data memory(ram) size is limited, few Kb's. Our processor runs sequential routines to store and access data from data memory. Placing data in specific ram location/address disturbs these sequential routines and processor has to jump to specific address for storing and retiring our data. On the other hand it is useful in case if we want our data to be accessed and processed faster by processor. Since data in placed in ram, we do not need it to load from program memory. Thus time to fetch the data from program memory(rom) is reduced.
Do not reserve large chunks of addresses/locations for data in data memory(ram). If the data memory(ram) is flooded with the reserved addresses/locations, their will be no space left for variables/data that needs to be loaded in the memory while our program is running. I recommend to only place the data in memory which is continuously required by the system or data that is highly fetched by the processor for manipulation and generating output, and this output is directly related to the system performance.
We can use '@' qualifier to access the address of microchip pic microcontroller ram using xc8 compiler. With '@' qualifier we not only can access ram addresses, we can also access program memory(rom) address. In this project i am also using '@' qualifier to access the ram location/address. Their are other two methods through which we can access the ram and rom but they are little difficult to manage. These two methods utilizes the compiler special directives.
Do not reserve large chunks of addresses/locations for data in data memory(ram). If the data memory(ram) is flooded with the reserved addresses/locations, their will be no space left for variables/data that needs to be loaded in the memory while our program is running. I recommend to only place the data in memory which is continuously required by the system or data that is highly fetched by the processor for manipulation and generating output, and this output is directly related to the system performance.
We can use '@' qualifier to access the address of microchip pic microcontroller ram using xc8 compiler. With '@' qualifier we not only can access ram addresses, we can also access program memory(rom) address. In this project i am also using '@' qualifier to access the ram location/address. Their are other two methods through which we can access the ram and rom but they are little difficult to manage. These two methods utilizes the compiler special directives.
- __section()
- __at()
I am going to allocate address in ram of pic16f877 microcontroller. I am using mplabx with xc8 compiler for writing and compiling code. You can see the code syntax in the picture on right side.
Addresses 0x70, 0x71 and 0x72 are allocated for integer variables ramloc1, ramloc2 and ramloc3. Please see the syntax of the code its
|
Note: After @ their is a one digit gap between the address and @ qualifier.
In the main function variables are initialized with data. I initialized variables with hex data 0x45 =69(decimal), 0x22=34(decimal) and 0x34=52(decimal). Initializing with hex data is easy to see in the ram file registers of mplabx ide. |
After putting the data at ram locations/addresses i run the project code simulation in mplabx ide and viewed the data memory addresses. Our data is placed at the same locations/addresses where we wanted it to be at addresses 0x70,0x71 and 0x72.
|
No comments:
Post a Comment