Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difficult pointer definition 1

Status
Not open for further replies.

Dawee1

Technical User
Aug 29, 2008
2
0
0
CZ
Hello,
I have problem to understand the code below:

Code:
#define LCD_DATA_REG (*(unsigned char*)( 0xC000 )) // Data Register
#define LCD_CTRL_REG (*(unsigned char*)( 0x8000 )) // CTRL Register

I know basics about pointers and I know how to understand pointers to functions, arrays, structures, int, ... However
I don't understand these definitions at all. Would anybody of you be so kind to explain me what these lines of code
means in detail? I would be very glad if you'll explain it step by step:

1. (unsigned char*)( 0xC000 ) - can number (0xC000) be a pointer? or what does this line mean?
2. (*(unsigned char*)( 0xC000 )) - what does the other symbol * mean?
...

Thank you and sorry for bothering you with this maybe easy problem.
 
Code:
0xC000
A hexadecimal number. Possibly gleaned from a hardware manual that says something like "The data register is at memory address 0xC000."

Code:
(unsigned char*)( 0xC000 )
A casting of that hexadecimal value to a pointer. It tells the compiler, "I realize it looks like I just made up this number, but I know what I'm doing and I really want you to treat it as a pointer to an unsigned character at the 0xC000 memory location."

Code:
*(unsigned char*)( 0xC000 )
A dereference of the resulting pointer. The unsigned character at memory location 0x2000.

Code:
#define LCD_DATA_REG (*(unsigned char*)( 0xC000 ))
You don't want to type that all the time, so you make a macro definition for it.

Now, you can do:
Code:
LCD_DATA_REG = value;
to write value to that memory location.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top