How to use upper 128byte of AT89S52. i.e. SFRs(80H to FFH) Address indirectly with KEIL C51 for general purpose which are not in use. They are directly addressable only as SFR.
according to datasheet: 1. The lower 128 bytes of RAM (00H to 7FH) are directly and indirectly addressable. 2. The higher 128 bytes of RAM (80H to FFH) are indirectly addressable. 3. The special function registers (80H to FFH) are directly addressable only.
Please help me thanks!
I know how to do it in assembly. But in C51 i miss this easy DPTR things.
in C if your variable is in XDATA, DPTR is used, no concern of yours.
Erik
How to use upper 128byte of AT89S52 in C51? please help me. one/two line example please.
IDATA
Yes, for you, here is a real exampel. not Please read the manual.
void clear_internal_idata_space ( void ) { char idata *Pointer_To_IDATA_Space - 0x80; int Counter; for ( Counter = 0x80; Counter <= 0xFF; ++Counter ) Pointer_To_IDATA_Space [ Counter ] = 0; }
Professor Zeusti.
nooooooooooo............
the line you want is this ...........
char idata *Pointer_To_IDATA_Space = 0x80;
Zeusti.
the one who does.
Interesting code there, professor.
So if the pointer gets initialized to 0x80, and you then use it as an array with offset values of 0x80 to 0xff, exactly where will you address the memory?
And another thing - you have designed a loop where your 8-bit processor will require a 16-bit counter just to be able to detect when it is time to leave the loop. What was wrong with designing the loop in a way that an 8-bit variable can be used?
the student commmments help me improve the exampel!
void clear_internal_idata_space ( void ) { char idata *Pointer_To_IDATA_Space = 0x80; unsigned char Counter; for ( Counter = 0x00; Counter <= 0x7F; ++Counter ) Pointer_To_IDATA_Space [ Counter ] = 0; }
but the idata is a real eamplel of how to see the memory.
idata char aVariable; is all he needs
This is C you do not write to unallocated space.
data char aVariable; idata char aVariable; pdata char aVariable; xdata char aVariable;
Then use the variable normally.
char aVariable; This goes into the space chossen by the memory model you chose.
Aha, I see.
Look, "Professor", I really don't want to hurt your feelings but you need to, urgently:
* Open a C text book and read it (I know there are no pictures there like you are probably used to, but try it anyway). * Learn how a C51 works. * Stop this arrogance campaign which, frankly, makes you look less "professor" than you would like to admit. * Stop giving wrong and misleading advise to people that think you are some kind of big-shot which you are not. Anybody that has a minimum knowledge regarding programming (not necessarily embedded) can see that! Spare us.
Tamir is right!
Don't misguide!
if looking for advice, ignore all posts from Zeusti
You'll probably think I'm a Zeusti affiliate for saying the following, but here goes anyway.
The OP asked:
"How to use upper 128byte of AT89S52 in C51?" "one/two line example please."
Zeusti gave:
Now, he may have the precise location of idata incorrect (it is a while since I used such a keyword), but fundamentally, I can see nothing wrong with the line.
Contrary to some of the replies, I don't see that as miguiding or misleading!
Heck - Have you people have never seen a need to access the memory in that manner (C or ASM)?
The valid example also given of:
idata char aVariable;
is an alternative, but it is only that, an alternative.
In my view it is no more or less right. The suitability of each would depend upon the particular requirement.
Rather than knocking Zeusti, it might be more helpful (at least to the OP) to explain when it might be suitable and what problems there might be.
Trevor, To my humble opinion the professor's rather unusual code originates from poor understanding of C. I particularly dislike his staunch arrogance and misguided self esteem. does he sound to you like somebody with a deep understanding of the subjects at hard? I don't think so.
one more thing Trevor: our self proclaimed "professor" has been around here for a while now (have you not encountered his pearls in the past?) doing more or less of the same like he has been trying to do in this thread. posting mistakes is alright - I do so myself sometimes - but misleading as he does (on a public forum) is another story!