Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Reading/writing register using macros in a single line in C

Status
Not open for further replies.

shaikss

Full Member level 4
Joined
Jun 18, 2007
Messages
229
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
3,319
Hi,

I need a small help.
I want to read/write a register by using C code.
By using pointers, its easy.
How to read/write a register using macros?
Just by using a macro, it has to read/write a value.
You should n't use pointers at all.
Pls help me on this.
 

Re: Help in C

It's simple to read/write uC register in C. For the example,

P1 = 0x0001;

This will set Port 1 to 0x0001

Is answer to your question?
 

Re: Help in C

I will tell u one example.
I want to read a register located at 0xFFFFF00F which contains data 0xFFFF.
Can u pls tell me how to write a C code by simply using macros?
By just defining a macro, it has to read the value from the register.
 

Re: Help in C

It depends on what particular C compiler you use. I will refer to SDCC which are used in my work [see my blog]


__sfr __at 0xFFFFF00F Var; /* Define Var address at 0xFFFFF00F */

void main(){
Var = 0xFFFF;
}


You also don't forget to mention what CPU/MCU you are using.
 

Help in C

if u want to read the register use the register name and copy the data into it.

i.e if the register name is P1 and u want to read

take a variable Var1.

Var1=P1.

if you do like that u can read the contents of the register.

if it is port, donot forget to make the port as input port.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top