hello everyone, i am quite new to programming 8051..hoping to receive some help.. i have a pointer variable.The address stored in this variable resides in the on-chip XRAM.
unsigned char xdata *xloc;
i need the control of my program to be transferred to this address..how can it be done in C??? Thank You in advance for the help..
Then you first need to spend some time familiarising yourself with the architecture - there's a few ways in which it is quite different from others you may know:
www.8052.com/.../120112
http://www.8052.com/tutorial
"i need the control of my program to be transferred to this address"
What, exactly, do you mean by that?
Note that the 8051 architecture has separate Code and Data memory spaces...
there are certain opcodes that i've stored in the xdata space...the control of the program has to be transferred there...the system firmware is ofcourse stored in the code space,but this is a user-interactive project,something like a trainer kit...the user program memory is stored in the xdata space, to which i need to pass control....
So have you selected a chip - or implemented external hardware - that allows your device to map XDATA memory into the CODE data space?
If you haven't, then you are stuck having started to implement something you can't finish. The 8051 chip will only execute from CODE. So any "user-interactive project" that should allow someone to download applets to run just have to place that applet within CODE. Either with a chip that has IAP (In Application Programming), where you can reprogram some of the CODE flash memory. Or with a chip or external hardware that allows an area of XDATA and CODE to overlap so you can write your data to XDATA and then access it through CODE.
the '51 is harward architecture en.wikipedia.org/.../Harvard_architecture
the user program memory is stored in the xdata space, to which i need to pass control.
why do you think it's called XDATA?
Erik
8051 Basics Time:
The 8051 architecture can not execute instructions from anything other than CODE space.
Also, the 8051 archicture has no instruction to write to CODE space - the CODE space is strictly read-only.
Therefore, the only way to achieve this is by some proprietary extension - such as mapping memory into both CODE and XDATA spaces.
How have you achieved this?
i am quite new to programming 8051
Given that, you shouldn't even be thinking of doing anything like the following. You're diving well beyond your depth.
i need the control of my program to be transferred to this address..how can it be done in C???
Oh, and it's impossible, too. The 8051 will not execute xdata.
ok 8051 cannot execute anything that resides in xdata...i get the point...but is there any way i can make the program to simply jump to an address location stored in a pointer variable in C?
you can use a function pointer to make a function call.
You can use a GOTO to jump to a label. But that usually makes your code a mess and it is not recommended.
i tried using a function pointer...
static unsigned int s_addr; unsigned char xdata *xloc; void (far *MyFunc)(void)=(void far*)(xloc); void main (void) { s_addr=get_addr(); xloc=(unsigned char xdata *)s_addr; (*MyFunc)(); }
but the 3rd line shows error MAIN.C(30): error C141: syntax error near '*', expected ')' MAIN.C(30): error C129: missing ';' before ')' get_addr() is a function which returns the address to which i need to make the jump...
There are some major issues with function pointers in Keil C51 - do not use them until you have thoroughly studied & understood the issues!
Start here: http://www.keil.com/appnotes/docs/apnt_129.asp
http://www.keil.com/support/man/docs/bl51/bl51_ol_fp.htm http://www.keil.com/support/man/docs/lx51/lx51_ol_fp.htm
And many more: www.keil.com/search.asp
And many previous discussions: www.keil.com/search.asp
What, exactly, is the purpose of this "trainer kit" ?
As already noted, the fundamental 8051 architecture means that it is not well-suited for loading user programs as you describe.
Therefore, if it is suppoosed to be specifically an 8051 trainer, you will be doing your students a disservice by suggesting that they use an 8051 in such an application.
On the other hand, if the purpose is to demonstrate loading user programs as you describe, then the 8051 is a poor choice.
In conclusion:
Either drop the "user program" idea - and concentrate on what an 8051 is useful for;
Or use a more appropriate processor to demonstrate the "user program" idea.
That doesn't mean that your students cannot load their own programs!
It just means that the way you're proposing is not the way to do it on an 8051 - and, therefore, not the way to teach it on an 8051!
Teach your students to use the normal ISP (In-System Programming) or IAP (In-Application Programming) approach for an 8051 .
That's because the the 3rd line is wrong! It's nothing to do with Keil or the 8051 - it's just not valid 'C' syntax.
You need to go back to your 'C' text book for details of how to do function pointers in the 'C' programming language in general.
Then you need to study the Keil Manuals for the Keil-specific details - and all the limitations - of function pointers in C51.
But, again, this is really not a great thing to be doing on an 8051 at all!
yea you are right..storing the opcodes in the xdata space is not going to do any good and also there are chances of them being over-written since xdata space is read/write...but this supposed trainer kit has already been implemented...and as per the manual the upper 32K bytes of an external RAM IC is meant for the user program memory...they probably have some mapping between the xdata and code space....will check properly...anyways thanQ for all the help and links...greatly appreciate...:)