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

PBYTE to sfr?

I have the following function:

void usbReceive(PBYTE Buffer, BYTE size);

and I want to pass an sfr to it:

usbReceive(&P2, 1);

I'm getting illegal pointer conversion
Nevertheless,
usbReceive(P2, 1);
does not compile also. How can I read directly into P2 sfr?

Parents
  • "I declare the 2-byte variable in internal memory (idata)."

    Depending on your (re)definition of PBYTE (which you didn't supply), it could well work.

    But now you've changed the question - you were asking about SFRs before!
    The reason why it can't ever work with an SFR (irrespective of any definition of PBYTE) has already been explained.

Reply
  • "I declare the 2-byte variable in internal memory (idata)."

    Depending on your (re)definition of PBYTE (which you didn't supply), it could well work.

    But now you've changed the question - you were asking about SFRs before!
    The reason why it can't ever work with an SFR (irrespective of any definition of PBYTE) has already been explained.

Children
  • As Hans said, you can't have a pointer to an SFR.

    The 8051 has 256 internal memory locations. Addresses 0..7FH are the "data" space (along with the registers and bit-addressable data). Addresses 80H..FFH are either internal ram ("idata") OR SFRs. But how does the processor know the difference? Any instruction using direct memory addressing modes accesses the SFR space. Any instruction using indirect addressing modes (pointers) accesses the memory space instead.