Is it possible to assign a structure (in C) with defined bit-fields to a SFR that is not bit addressable to gain bit addressability ?
I'm reading a book titled "Embedded Multitasking with Small Microcontrollers" by Keith E. Curtis. In chapter 2 he spends several pages stating the usefulness of STRUCTURES for creating control and data variables linked to "system peripherals". He makes a convincing argument for using them, shows examples and promotes usage for organizational value.
I'm trying to determine if I agree with his advise. I realize the usefulness of "|=" and "&=". That is how I do bit operations on bytes now. I'm trying to expand my knowledge by listening to others (read books on the topic) to see if I may learn something new and useful...
You have replied twice but still haven't answered the question of how to link an SFR to a structure. The author states this is compiler dependent.
You can't link an SFR to a structure. But you can place a structure at an absolute location, which I did mention.
Guess how many people who have asked how to place a variable at an absolute address on tis forum? Guess how many answers that have been given?
Being compiler dependent means its normally documented in the compiler manual. What do you think happens if you read the Cx51 users manual and look at the section named "Absolute Variable Location"? http://www.keil.com/support/man/docs/c51/c51_le_absvarloc.htm
"Guess how many people who have asked how to place a variable at an absolute address on tis forum? Guess how many answers that have been given?"
"What do you think happens if you read the Cx51 users manual and look at the section named "Absolute Variable Location"?"
What's your point?
I hope it's because English is not your native language and your grammar is subpar. Your attitude is borderline condescending. I've been designing hardware for nearly 30 years but when it comes to writing C on a uC I'm a novice. Your technique of answering a question with a question is not appreciated nor appropriate. Don't reply if you think these questions are beneath you.
By the way, I've got a copy of the manual and referred to it many times. Do you think I haven't already read the pages that you sent a link to? What do you think? Why do you hang-out on this forum?
So if you have multiple times been reading the relevant manual pages, you'll just have to use your impeccable grammar and write a better question, letting other forum users know that you do know about that manual section and know exactly where you are stuck.
I wasn't answering a question with a question when I did tell you that an SFR can't be moved. So the way to get a struct on top of an SFR is obviously to move that struct to the correct location. The 8051 is lousy with pointers, so initializing a pointer to the address of the SFR bank and then access the registers indirectly through the pointer will give truly lousy results. Having a struct statically located on top of the SFR allows the compiler to ignore the offset of individual fields in the struct and use best possible addressing modes.
What information did you found lacking in the linked manual page.
so initializing a pointer to the address of the SFR bank and then access the registers indirectly through the pointer will give truly lousy results the SFRs in a '51 is only directly addressable
I would call that truly lousy results ;)
The thing with many programming books is that they are often written for more general-purpose processors even when they claim to be about embedded programming. Embedded is everything for a 4-bit processor with assembler software to a Linux-based system 100 times faster than the original PC.
Structures are heavilly used for ARM Cortex processors. But it does have full generic addressing modes. 8051 compilers normally doesn't even use normal stack space for parameters and local variables. Everything to try to get the best out of the chip with the instructions and addressing modes that exists.