|
|||||||||||
|
Technical Support Support Resources
Product Information |
C51: General Purpose SFR InterfaceInformation in this article applies to:
QUESTIONI would like to create a general purpose interface function that would allow me to access the sfr's. I have created CmdRI() and CmdWI() functions which read and write idata:
At first I expected that the type cast on line 13 would cause the code to read data from the sfr's if the value of addr was between 0x80 and 0xff. The debugger shows me that the compiler reads the data from idata and not the sfr's. Can you recommend any way to get to the sfr's in a general fashion? I want to use the same command format as for simple memory read/write commands. ANSWERUnfortunately, there's no way to do that. The SFRs in the 8051 are directly addressable only. That means that the address must be a part of the program. There is no way to indirectly address the SFRs. So, pointers won't work. Take a look at the Intel documentation on the internal data memory and it should become clear. One way to "sort of" do this is to define an SFR for each SFR address and use a big switch statement as follows:
This is not a really elegant solution, but it will work. The READ function should be similar. MORE INFORMATION
SEE ALSO
Last Reviewed: Thursday, February 25, 2021 | ||||||||||
|
|||||||||||
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.