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

SFR access without keyword "sfr"

Hi,

I'm trying to access SFR memory using the hexa address of the SFR
and using only "C" instructions.
Since SFR memory is accessed by direct addressing mode, like the first
128 bytes of internal RAM, I tried to use the following instruction :

* ((unsigned char data *) 0xA8) = 0x1;
Unfortunately the generated code is :
MOV  	R0,#0A8H
MOV  	@R0,#01H
which is indirect addressing and points to the upper 128 bytes of
internal memory (in a 8052) or nowhere (with 8051).

If I try to address specificly the upper 128 bytes of internal RAM using
* ((unsigned char idata *) 0xA8) = 0x1;
then the generated code is :
MOV  	R0,#0A8H
MOV  	@R0,#01H
which seems to be correct.

I think I miss something but I don't see what.
Anybody can help ?

Thanks in advance.

Arnaud

Parents
  • *((unsigned char data *) 0xA8) = 0x1;
    
    Unfortunately the generated code is :
    
    MOV  	R0,#0A8H
    MOV  	@R0,#01H

    Which is exactly what should happen. The SFR's are not memory, the are registers. You cannot take the address of a register, thus you cannot point to it. You must use sbit, sfr, or sfr16 to access the 8051 registers. I.e.

    sfr someBit = 0xA8;
    someBit = 0x12;

    This is a major pain when you have two UART's and would like to pass in a UART context to multiply instantiated UART driver code.

    - Mark

Reply
  • *((unsigned char data *) 0xA8) = 0x1;
    
    Unfortunately the generated code is :
    
    MOV  	R0,#0A8H
    MOV  	@R0,#01H

    Which is exactly what should happen. The SFR's are not memory, the are registers. You cannot take the address of a register, thus you cannot point to it. You must use sbit, sfr, or sfr16 to access the 8051 registers. I.e.

    sfr someBit = 0xA8;
    someBit = 0x12;

    This is a major pain when you have two UART's and would like to pass in a UART context to multiply instantiated UART driver code.

    - Mark

Children