This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

bit addressing

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?

Parents Reply Children
  • 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...

  • I would have thought not?

    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.