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?
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...
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.