|
|||||||||||
Technical Support Support Resources
Product Information |
C51: How to Directly Address Multiple Consecutive SFRSInformation in this article applies to:
QUESTIONCan I use structures to access data in the direct area of my 8051? I would also like to address several byte wide SFRs as one data element. I wrote the following code:
But this generates an indirect read through a register. Is there a more optimal solution to this problem? ANSWERIt is not possible to locate variables of any kind, except sfrs, in the SFR memory area. When you located the union at BCH and obtained indirect addressing, you were actually accessing the portion of idata that resides between 80H and FFH. This overlays the SFR area, which also resides between 80H and FFH. In fact, when you locate any variable between 80H and FFH, it is located in idata, not the SFR area. However there are two ways to solve this problem 1. Solution directly in the C LanguageOne solution is to declare each SFR with a separate name and perform shifting operations. For example:
Another more optimal solution uses type casting:
The code generated for this solution appears as follows:
2. Solution via Assembler defineIn assembly language you may define the address of the SFR as a PUBLIC symbol. For example:
Now you may access the SFR as a long value in the C source code by using an extern variable definition:
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.