Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how to access memory location in embedded c?

Status
Not open for further replies.
hi.

i want to know that how to access memory location in embedded c?

i have 1 register a and i want to store this in memory location 0x501 than how should i defined??
 
In Hi-tech C its...
Code:
volatile unsigned char Portvar @ 0x06;

which equates to

Code:
_Portvar EQU 06h

straight out of the manual..... Absolute variables.....

My question.... Why? In C you can create a pointer to a variable anyway! I've NEVER needed this facility.
 
Create a location..

Code:
char x;
This maybe anywhere in data memory..

Create a pointer...
Code:
char * ptr;
Now you dont need to know where it is..

Point at the variable.
Code:
ptr = &x;

&x; the address of x... x and ptr are now referenced..
Code:
x=5;
*ptr = 5;

You can also create a pointer to a constant..

Code:
const char * cp;
const char inputData[1000] @ 0x900;
cp = &inputData;
// cp is incremented over inputData and used to read values there

(Straight out of the manual...)
 
Why you need to do this. All of the SFRs are mapped to correct locations by the processor header files.

We define linker sections to memory ranges, are you trying to get around that ?

Exactly....... As I said, all my years I have never needed this....
 
Why you need to do this. All of the SFRs are mapped to correct locations by the processor header files.

We define linker sections to memory ranges, are you trying to get around that ?
Well they weren't in 1988 when I started using the IAR C compiler for the 68HC11.
 
hi..

thanks for your reply. How to use pointer to indicate memory locations?
wtp pepper, i used your technique but it doesn't store data.

Some registers are write only and do not return the value that was written. They are latches. You are best as said elsewhere keeping a local variable as to what has been written and modifiying that before writing to a port. The example I gave works for writing to a Port and reading from a memory location.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top