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
  • PBYTE, by its very definition in the manual, cannot possibly point to an SFR, because SFRs don't live in external memory.

    You might have more luck using DBYTE, but don't count on it --- SFR's can't be accessed by indirect addressing, which in terms of normal C means that a pointer to an SFR is impossible to do.

Reply
  • PBYTE, by its very definition in the manual, cannot possibly point to an SFR, because SFRs don't live in external memory.

    You might have more luck using DBYTE, but don't count on it --- SFR's can't be accessed by indirect addressing, which in terms of normal C means that a pointer to an SFR is impossible to do.

Children
  • If you think that PBYTE is a pointer to xdata then claryfy me, please, how does this work:

    void send_buffer(PBYTE buf, BYTE size) {
    	BYTE s;
    	for (s = 0; s < size; s++)
    		send_byte(*buf++);
    }
    WORD w = 11;
    send_buf(&w, 2);
    
    I declare the 2-byte variable in internal memory (idata). Why do I receive it by rs232 in PC correctly?

  • "If you think that PBYTE is a pointer to xdata then claryfy me"

    To find the explanation, open the online Manual and search for PBYTE.

  • "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.

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