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

Address bits in XDATA

Hi, I am looking for a way to write some C51 functions to set or clear bits stored in the 8051 external data memory. For example, the following code was done in the 8051 assembly language:

;*******************************
SYSTEM_TROUBLE1   XDATA   1000H
AC_FAIL   ACC.0
LOW_BAT   ACC.1
.
.
SYSTEM_TROUBLE2   XDATA   1001H
TELCO1_FAIL   ACC.0
TELCO2_FAIL   ACC.1
.
.
;*******************************
.
.
MOV DPTR, #SYSTEM_TROUBLE1
MOVX A, @DPTR
SETB AC_FAIL
MOVX @DPTR
.
.
How can I implement such function in C51? Thanks.

Parents Reply Children
  • Can you give an example?

    The following looks pretty good.

    xdata struct 
    {
      char AC_FAIL :1;
      char LOW_BAT :1;
    } SYSTEM_TROUBLE1  _at_ 0x1000;
    
    
    void main( void )
    {
      if( SYSTEM_TROUBLE1.AC_FAIL )
        SYSTEM_TROUBLE1.LOW_BAT = 1;
    }
    
                 ; FUNCTION main (BEGIN)
    0000 901000            MOV     DPTR,#SYSTEM_TROUBLE1
    0003 E0                MOVX    A,@DPTR
    0004 30E003            JNB     ACC.0,?C0002
    0007 4402              ORL     A,#02H
    0009 F0                MOVX    @DPTR,A
    000A         ?C0002:
    000A 22                RET     
                 ; FUNCTION main (END)
    

  • Opps, sorry, I picked the wrong flag to test. You are correct, bit fields are inefficient.
    
    It would also be great if the compiler also optimized:
    <bitfield> <op> <const> or <const> <op> <bitfield> 
    Where <op> is ==, !=, <, >, <=, >=, &&, ||
    
    xdata struct 
    {
      char AC_FAIL :1;
      char LOW_BAT :1;
    } SYSTEM_TROUBLE1  _at_ 0x1000;
    
    
    void main( void )
    {
      if( SYSTEM_TROUBLE1.LOW_BAT )
        SYSTEM_TROUBLE1.AC_FAIL = 1;
    }
    
                 ; FUNCTION main (BEGIN)
    0000 901000            MOV     DPTR,#SYSTEM_TROUBLE1
    0003 E0                MOVX    A,@DPTR
    0004 FF                MOV     R7,A
    0005 C3                CLR     C
    0006 13                RRC     A
    0007 30E004            JNB     ACC.0,?C0002
    000A EF                MOV     A,R7
    000B 4401              ORL     A,#01H
    000D F0                MOVX    @DPTR,A
    000E         ?C0002:
    000E 22                RET     
                 ; FUNCTION main (END)
    

  • Opps, sorry, I picked the wrong flag to test. You are correct, bit fields are inefficient.

    Uhhhh. You only tested one case of bit-fields -- a 1-bit bit-field. I would make more tests before making such a broad, sweeping statement.

    Anyway, what is so inefficient about the code that was generated?

    Jon

  • Graham,

    Thanks for that. I missed your earlier post. The points you make are very good and I've passed them on to engineering to incorporate in a future release.

    Jon