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...)
 
I wonder if 0x501 is in data or program memory or even both!!

Mike.
 
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 ?
 
Last edited:
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.
 
hiren.dave Is an expert at NOT answering questions.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…