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

Accesing bit addressable variables

I was wondering what the "best" way to set a bit in a variable declared in the bit addressable area.

Originally I declared each bit as an sbit and therefore can set and clear them as follows

uint8_t bdata status ;
sbit enable = staus ^ 0 ;

enable = 1 ;
enable = 0 ;
I think it looks clearer to do as follows
#define ENABLE 0x01

uint8_t bdata status ;

status |= ENABLE ;
status &= ~ENABLE ;

but I am worried that this could less maintainable because there will be many #defines with the same values but related to different variables and confusion could ensue.

I was wondering what other people do and if there is a standard method for doing this?

Parents
  • It looks like mine does. Maybe it has something to do with the way i have defined the variable.

    $NOMACRO
    $SEGMENTED CASE MOD167
    ;
    ; 'main.SRC' GENERATED FROM INPUT FILE 'main.c'
    ; COMPILER INVOKED BY:
    ;	C:\Keil\C166\BIN\C166.EXE main.c BROWSE MOD167 DEBUG
    ;
    $MODINF (43)
    		 NAME MAIN
    
              NCODE  CGROUP  ?PR?MAIN
              SDATA  DGROUP  ?BD0?MAIN,SYSTEM
    
                     ASSUME  DPP3 : SDATA
    
          ?BD0?MAIN  SECTION  DATA BITADDRESSABLE 'BDATA0'
             status  DSB  1
             PUBLIC  status
          ?BD0?MAIN  ENDS
    
              EXTRN  ?C_STARTUP : NEAR
             enable  BIT   status.0
             PUBLIC  enable
    
    
                     REGDEF   R0 - R15
    
    
           ?PR?MAIN  SECTION  CODE WORD 'NCODE'
    ; line 1: #include "types.h"
    ; line 2:
    ; line 3: #define ENABLE 0x01
    ; line 4:
    ; line 5: uint8_t bdata status ;
    ; line 6:
    ; line 7: sbit enable = status ^ 0 ;
    ; line 8:
    ; line 9: #pragma SRC
    ; line 10:
    ; line 11: void main ( void )
    
    	main  PROC  NEAR
    	GLOBAL  main
    ; FUNCTION main (BEGIN  RMASK = @0x8000)
    ; line 12: {
    ; line 13:
    ; line 14:
    ; line 15:
    ; line 16: 	enable = 1 ;
    	BSET	enable
    ; line 17: 	enable = 0 ;
    	BCLR	enable
    ; line 18:
    ; line 19: 	status |= ENABLE ;
    	BSET	(status).0
    ; line 20: 	status &= ~ENABLE ;
    	BCLR	(status).0
    ; line 21:
    ; line 22: 	while(1)
    ; line 23: 	{
    ; line 24:
    ; line 25: 	}
    ?C0001:
    	JMP	cc_UC,?C0001
    ; FUNCTION main (END    RMASK = @0x8000)
    	main  ENDP
           ?PR?MAIN  ENDS
    
    
    ; line 26:
    ; line 27: }
    
    	END
    

Reply
  • It looks like mine does. Maybe it has something to do with the way i have defined the variable.

    $NOMACRO
    $SEGMENTED CASE MOD167
    ;
    ; 'main.SRC' GENERATED FROM INPUT FILE 'main.c'
    ; COMPILER INVOKED BY:
    ;	C:\Keil\C166\BIN\C166.EXE main.c BROWSE MOD167 DEBUG
    ;
    $MODINF (43)
    		 NAME MAIN
    
              NCODE  CGROUP  ?PR?MAIN
              SDATA  DGROUP  ?BD0?MAIN,SYSTEM
    
                     ASSUME  DPP3 : SDATA
    
          ?BD0?MAIN  SECTION  DATA BITADDRESSABLE 'BDATA0'
             status  DSB  1
             PUBLIC  status
          ?BD0?MAIN  ENDS
    
              EXTRN  ?C_STARTUP : NEAR
             enable  BIT   status.0
             PUBLIC  enable
    
    
                     REGDEF   R0 - R15
    
    
           ?PR?MAIN  SECTION  CODE WORD 'NCODE'
    ; line 1: #include "types.h"
    ; line 2:
    ; line 3: #define ENABLE 0x01
    ; line 4:
    ; line 5: uint8_t bdata status ;
    ; line 6:
    ; line 7: sbit enable = status ^ 0 ;
    ; line 8:
    ; line 9: #pragma SRC
    ; line 10:
    ; line 11: void main ( void )
    
    	main  PROC  NEAR
    	GLOBAL  main
    ; FUNCTION main (BEGIN  RMASK = @0x8000)
    ; line 12: {
    ; line 13:
    ; line 14:
    ; line 15:
    ; line 16: 	enable = 1 ;
    	BSET	enable
    ; line 17: 	enable = 0 ;
    	BCLR	enable
    ; line 18:
    ; line 19: 	status |= ENABLE ;
    	BSET	(status).0
    ; line 20: 	status &= ~ENABLE ;
    	BCLR	(status).0
    ; line 21:
    ; line 22: 	while(1)
    ; line 23: 	{
    ; line 24:
    ; line 25: 	}
    ?C0001:
    	JMP	cc_UC,?C0001
    ; FUNCTION main (END    RMASK = @0x8000)
    	main  ENDP
           ?PR?MAIN  ENDS
    
    
    ; line 26:
    ; line 27: }
    
    	END
    

Children