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.
In my application, I want to easily change address of SFR include user's commands. Such as: sbit ram_en=P1^0; ...... /*In another place, I want to change ram_en to P1^2 dynamiclly.*/ I am try to do this(not definition field) in my code: ... sbit ram_en=P1^2; .... But it can not pass when compiling. So, how can I implement this function? Best regards!
In other words, how can I redefine sfr's in program field,such as: main() { .... sbit ram_en=P1^2; .... }
Oh, I forgot that I use C51 structure process... Thanks for your comment!
"C51 structure process" What on earth is that?
NO, you cannot do this. The 8051 instruction set has no way to indirectly address SFRs. This is part of the processor architecture - nothing to do with any particular toolset. You will have to do something like:
sbit ram_en0=P1^0; sbit ram_en1=P1^2; : if( whatever ) { // use ram_en0 } else { // use ram_en1 }
Sorry, that's my mistake, it should be "processor"... I have one idea to make some C51 learning system that user can directly modify some interface definition from console. Such as, user can either connect IIC device to P1.0 and P1.1, or P3.0 and P3.1, they just need redefine SDA from P1.0 to P3.0, etc. Thus it does not need re-compile code. This can give user more flexibility and more convenience. Best regards!
"Sorry, that's my mistake, it should be 'processor'..." Hmmm... "C51 structure processor" still doesn't mean anything. What do you mean? "Thus it does not need re-compile code. This can give user more flexibility and more convenience." Well, yes - more flexibility and more convenience, but fundamentally impossible on an 8051! I think you would be misleading your students by suggesting that they can do this without having to recompile. Anyhow, how long does it take to recompile such student projects?
Hehe, I believe it will take less time to re-compile project code. But I just want to make one system that can cast off IDE and programmer when I change some pin functions, that's it. If so, it seems I have to give up this idea.... Thanks for your help!
You might be able to do this using the Crossbar feature on (some of) the Silicon Labs (nee Cygnal) parts...
OK, I see, thanks again!
There is a way around this limitation, if you're doing your own hardware: create a von-Neumann wired RAM area and write self-modifying code into it.
Take a look at the following knowledgebase article for an idea you may find useful: http://www.keil.com/support/docs/101.htm Jon
http://www.keil.com/support/docs/101.htm Jon, that still requires re-building the Project; Tomy wants to have this dynamically reconfigurable at run time...!
1) Self-modifying code. Requires execution out of RAM, and mapping program store into xdata space so that you can write to it. Such programming developed an evil reputation back in the day before people stopped feeling so squeezed they had to do it. 2) Step back from the bits, and just read the whole port byte. You can then keep a variable for your current desired bit position. Instead of
if (my_sbit)...
U8 my_mask = 1 << my_bit; if (P1 & my_mask)...
U8 my_bit; bit result; switch (my_bit) { case 0: result = P1^0; break; case 1: result = P1^1; break; case 2: result = P1^2; break; ... } // use result
"2) Step back from the bits, and just read the whole port byte." But he also wants the port number to be run-time configurable - not always P1! So he'd have to do this in conjunction with (3).
I missed that requirement. There are no pointers to SFRs possible in the 8051 architecture. So, yes, you'd need another level of dispatching for the port byte:
if (ReadCurrentPort() & my_mask)