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!
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)
I have one idea to make some C51 learning system that user can directly modify some interface definition from console So, you are going to make a learning system that makes the "student" learn methods that are not possible in real life. Please keep us informed as to who learns from it so we can avoid hiring them. Thanks Erik