Do you have a question? Post it now! No Registration Necessary
- Posted on
- Everett M. Greene
December 1, 2003, 6:45 pm
Re: Trying to understand the workings of a Memory Mapped I/O
Here's my take on it. Firstly, these are C language preprocessor macro
definitions. The preprocessor's job is to substitute the token P0 with the
expression given in the definition;
((*(__R volatile unsigned char *)(unsigned char)0x0))
The C preprocessor is, in essence, a text substituter.
As to the meanings of the definitions, it can be analysed by proceeding from
the right towards the left. The numerical values, 0x0, 0x1, etc. are
Each of these constants is typecast to an unsigned char. This has two
1. To take only the least signifigant 8 bits of the integer constant. In
the case of your
values, this effects no change. It would if the values exceeded 0xFF.
2. Suppress any sign extension. It's the "unsigned" that does this. In the
your values, there is again no effect.
The typecast preceding this; "volatile unsigned char*" means regard the
expression to the right of this typecast as a pointer to an unsigned char.
i.e. the expression is to be regarded as an address.
The "volatile" word tells the compiler not to assume that the unsigned char
pointed to will retain its value between accesses; i.e. it might be changed
by external events.
The "__R" qualifier is non-standard and I don't know what it means. I would
guess it might mean register, as the names P0, P1, etc. seem to be register
Finally the '*' preceding this typecast means the contents of the address
the value at the specified address.
P0,P1,P2,P3 are the names of the ports on a standard 8051 processor, but
respective addresses are 0x80, 0x90, 0xA0, 0xB0 respectively, so if the code
were to refer to an 8051, there leaves something about the definitions yet
David Bardon, Avocet; firstname.lastname@example.org