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; .... }
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 }