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

How The sbit keyword works

how can an sbit variable be assigned an address which is intrinsically assigned to something else.
e.g will the following code work on an 8051?

sfr SCON = 0x98; // declare SCON
sbit SM0 = 0x9F; // declare sbit members of SCON
sbit SM1 = 0x9E;
sbit SM2 = 0x9D;
sbit REN = 0x9C;
sbit TB8 = 0x9B;
sbit RB8 = 0x9A;
sbit TI = 0x99;
sbit RI = 0x98;

Address 0x9A is the address for a special function register. IEN2. Won't the RB8 and this SFR conflict?
I'm especially interested in how the compiler interprets the "sbit" keyword.

Thanks in advance

Parents
  • Byte and bit addresses are two separate address spaces, even if they can access the same data.

    The processor is using one set of instructions to access sbit variables, and a different set of instructions to access byte variables. That is the reason why an sbit can have the same numeric value for the address as the data byte has.

    You can also have a byte in code space that has the same address value - code is yet another address space. Do read up on the different address ranges in the 8051 processor, and the different assembler instructions used when accessing the different address spaces.

Reply
  • Byte and bit addresses are two separate address spaces, even if they can access the same data.

    The processor is using one set of instructions to access sbit variables, and a different set of instructions to access byte variables. That is the reason why an sbit can have the same numeric value for the address as the data byte has.

    You can also have a byte in code space that has the same address value - code is yet another address space. Do read up on the different address ranges in the 8051 processor, and the different assembler instructions used when accessing the different address spaces.

Children