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.
are 8051 derivatives bit addressable on the ports like PICs are? if so how do you write this in c? if i waned to address P1.4 would i write P1=P1|0x10 or am i way off the mark?
the '51 is bit addressable for some entities, I have no idesa if it is like the PIGs. so how do you write this in c? if i waned to address P1.4 exactly as the manual tells you to. it seems obvious you have skipped the important 'familiarization' step of working through the examples in the "getting started guide"
Erik
"are 8051 derivatives bit addressable on the ports like PICs are?"
This is covered in the so-called "bible" for the 8051:
Chapter 1 - 80C51 Family Architecture: www.nxp.com/.../80C51_FAM_ARCH_1.pdf
Chapter 2 - 80C51 Family Programmer's Guide and Instruction Set: www.nxp.com/.../80C51_FAM_PROG_GUIDE_1.pdf
Chapter 3 - 80C51 Family Hardware Description: www.nxp.com/.../80C51_FAM_HARDWARE_1.pdf
"how do you write this in c?"
Only by means of implementation-specific extensions to the language - which must, of course, be covered in the compiler Manual. In this case, see: http://www.keil.com/support/man/docs/c51/c51_extensions.htm
In short: P1^1 = 1; And no you can not array them
But without (knowing) "the bible" you do not have the foggiest Idea what you can bitcheck and what not.
The post "why does tbit f7^3 not work" is not that infrequent.
I made the assumption that he only wanted the syntax for to get equivalent PIC single OP code. Though it would be easy enough to find in the manual. For the Hi-Tech PIC compiler "P1=P1|0x10" will produce a set bit opcode. I wonder if Keil does too?
I would have thought not?
The 8051 ports are inherently addressable as either a whole byte, or individual bits.
"P2" should represent the whole byte, so should generate a full-byte access. If the programmer wants to access an individual bit, they should code that as such - the compiler should not attempt to "second-guess" the programmer's intention.
Otherwise, how would the compiler decide when to stop doing individual bits, and use the whole byte: P1=P1|0x10 - a single-bit op? P1=P1|0x30 - 2 single-bit ops? P1=P1|0x70 - 3 single-bit ops? P1=P1|0xf0 - 4 single-bit ops? etc...
In short: P1^1 = 1;
Actually, afaik a caret (^) is only considered a bit-position operator when used in an sbit definition. In all other places, it is considered an XOR operator, so the line above will generate the appropriate error.
As far as I know, sfr/sbit are implicitly volatile, so the compiler is required to perform all accesses as stated in the code. Using a bit operation in a line like
P1 = P1 | 0x02
would actually be wrong behavior.