We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
How to use 24 bit addressing in keil for DP 8051.
We want it in C language.
can we declare a 24 bit address location as a register, similarly as we do in 8 bit address registers.
Ex. #define REG8 (*((volatile unsigned long int xdata *)(x))) // were REG8 is an 8 bit register and x is the 24 bit address
will this work when x is a 24bit adddress loaction?
What do you mean by "REG8 is an 8 bit register"?
REG8 is the name of a define - it has no actual meaning in itself.
The value returned when using the REG8 macro is an unsigned long.
#define REG8 (*((volatile unsigned long int xdata *)(x))
If in this case I take data type as char instead of long int it will be of 8 bit.
i.e.#define REG8 (*((volatile unsigned data xdata *)(x))
In previous case it is taken as long int it returns the 32bit value.
This ia an example.
If you intend to access 8 bits of unsigned data, you should write "unsigned char". If you just write "unsigned", it will return an unsigned integer which is 16 bits.
For size of data types, see: http://www.keil.com/support/man/docs/c51/c51_ap_datastorage.htm
And once more, do be careful about naming conventions. Your original definition of REG8 returned unisgned long, which for the C51 compiler is 32 bits.
If you have hardware memory-mapped into the far data space, then yes, a declaration similar to this will work. (The comments already made about data types are well put.)
Your hardware external to the 8051 will of course have to decode the 24-bit address bus and select whatever device it is that has these registers. The details will be in the data sheet for your particular 8051 variant.