Engineers Garage

  • Projects and Tutorials
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • EE Design News
    • DIY Reviews
    • Guest Post
    • Sponsored Content
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • Video
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering

Microchip xc8 compiler place data in ram specific location/address of pic microcontroller

August 25, 2019 By EG Projects

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.

  • __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

  • int ramloc @ 0x70; ​

reserve ram address for data using xc8 compiler for pic microcontrollers

reserve ram address for data using xc8 compiler for pic microcontrollers

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. 
Picture

Ram address allocation not allowed globally in xc8 compiler.

Initializing the address globally is not allowed in xc8 compiler. You can only initialize the variable in main line functions. Compiler did not recognize the statement, see the picture on left side
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.  
Pic microcontroller ram data placed at specific addresses and locations.

Pic microcontroller ram data placed at specific addresses and locations.

For tutorial on Placing data in specific location in rom using xc8 compiler visit 

  • How to place data at specific locations in rom/program memory using xc8 compiler. 
Download the project code written in mplabx ide. Folder includes all the mblabx files. Please provide us your feed back on the project. If you have any queries please write them below in the comments section.
Project Code/Files

Related Articles Read More >

TV remote hack using Arduino and IR sensor
Gesture sensor using Arduino
How to build a metal detector using an inductive proximity sensor with Arduino
Object follower robot using Arduino

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Getting Started with the ESPlorer IDE
  • SENDING TEXT MESSAGE USING ESP8266
  • CONNECTION BETWEEN TWO ESP8266
  • ESP8266 WIFI HOTSPOT
  • HOME AUTOMATION USING ESP8266
  • Open WiFi Scanner using Esp8266

Stay Up To Date

Newsletter Signup

EE Training Center Classrooms

“ee

“ee

“ee

“ee

“ee

Recent Articles

  • TV remote hack using Arduino and IR sensor
  • Gesture sensor using Arduino
  • Diodes adds to its family of voltage-level shifters
  • Xilinx expands UltraScale+ portfolio to include compact, intelligent edge solutions
  • New Armv9 architecture designed to increase security and AI capabilities

RSS EDABOARD.com Discussions

  • Help with damaged board
  • Sine Wave Generation with SPI and TIM interrupt in STM32
  • PIC BASIC
  • 4 switch buck boost converter
  • Question about hexagonal patch antenna frequency and design

RSS Electro-Tech-Online.com Discussions

  • Can MT8870 DTMF decoder module handles none audible signals?
  • What has happened to EEVBLOG videos?
  • Funny Images Thread!
  • Cell phone detector
  • Adjustable 0-5v ground switch
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2021 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • EE Design News
    • DIY Reviews
    • Guest Post
    • Sponsored Content
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • Video
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering