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
  • Thanks, I think I understand what an sbit variable really is now.

    I have also run into another problem. I tried setting Timer1 to free run mode and unmasking the overflow interrupt as a means of generating a pulse train output on one of the MCU pins. The trouble is that, while I can poll and detect changes to the overflow flag T1CTL.OVFIF, the interrupt function doesn't execute. Below is the very simple code I was trying to test interrupts with.

    
    #include "CC2430.h"   // for register declaration
    void main(void){
      P1SEL = 0x00;         // Sets PORT 1 pins to GPIO
      P1DIR = 0xFF;         // Set as outputs
      P1_3=1;                       //indicates the system's on
    T1CNTL = 0x00;          //reset the counter to zero
    T1CTL  = 0x0D;          //free running mode
    OVFIM = 1;              // Unmask overflow
                                //interrupt
    T1IE  = 1;              // enable Timer1 interrupt
    IEN0 = 0x80;            // enable all interrupts
    }
    
    void
    ISR (void) interrupt 9 { // timer one interrupt func
    
    P1=0xFF;      // turn on the LEDs connected to Port1
    
    }
    

Reply
  • Thanks, I think I understand what an sbit variable really is now.

    I have also run into another problem. I tried setting Timer1 to free run mode and unmasking the overflow interrupt as a means of generating a pulse train output on one of the MCU pins. The trouble is that, while I can poll and detect changes to the overflow flag T1CTL.OVFIF, the interrupt function doesn't execute. Below is the very simple code I was trying to test interrupts with.

    
    #include "CC2430.h"   // for register declaration
    void main(void){
      P1SEL = 0x00;         // Sets PORT 1 pins to GPIO
      P1DIR = 0xFF;         // Set as outputs
      P1_3=1;                       //indicates the system's on
    T1CNTL = 0x00;          //reset the counter to zero
    T1CTL  = 0x0D;          //free running mode
    OVFIM = 1;              // Unmask overflow
                                //interrupt
    T1IE  = 1;              // enable Timer1 interrupt
    IEN0 = 0x80;            // enable all interrupts
    }
    
    void
    ISR (void) interrupt 9 { // timer one interrupt func
    
    P1=0xFF;      // turn on the LEDs connected to Port1
    
    }
    

Children