typedef union{ Byte bits; struct { Byte VIDEO0 :1; // video mode bits Byte VIDEO1 :1; Byte ORIENT0 :1; // orientation bits Byte ORIENT1 :1; Byte FREQ0 :1; // frequency bits Byte FREQ1 :1; Byte LED :1; // LED enable bit Byte :1; // unused } bit; struct { Byte mrgVIDEO :2; Byte mrgORIENT :2; Byte mrgFREQ :2; Byte :1; Byte :1; } mergedbits;} vconfig_union;extern volatile vconfig_union vconfig;#define VCONFIG vconfig.bits#define VCONFIG_VIDEO0 vconfig.bit.VIDEO0#define VCONFIG_VIDEO1 vconfig.bit.VIDEO1#define VCONFIG_ORIENT0 vconfig.bit.ORIENT0#define VCONFIG_ORIENT1 vconfig.bit.ORIENT1#define VCONFIG_FREQ0 vconfig.bit.FREQ0#define VCONFIG_FREQ1 vconfig.bit.FREQ1#define VCONFIG_LED vconfig.bit.LED#define VCONFIG_VIDEO vconfig.mergedbits.mrgVIDEO#define VCONFIG_ORIENT vconfig.mergedbits.mrgORIENT#define VCONFIG_FREQ vconfig.mergedbits.mrgFREQ
Byte memory[8];
memory[7]= VCONFIG; not work? Also I'm not completely understand why you want to do this assignment, not sure how memory[7] could be simpler than using the VCONFIG, but there are certainly good reasons for copying a byte :smileyhappy:. Daniel
extern Byte memory[]; // Flash EEPROM memory typedef union { Byte bits; struct { Byte LEDS :1; // LED enable bit, 0 Byte SSVR :1; // screensaver bit, 1 Byte FREQ0 :1; // frequency bits, 2-3 Byte FREQ1 :1; Byte ORIENT0 :1; // orientation bits, 4-5 Byte ORIENT1 :1; Byte VIDEO0 :1; // video mode bits, 6-7 Byte VIDEO1 :1; } bit; struct { Byte :1; Byte :1; Byte mrgFREQ :2; Byte mrgORIENT :2; Byte mrgVIDEO :2; } mergedbits; struct { Byte memory[7] :8; } eeprombits; } config_union; extern volatile config_union config;
typedef union{ Byte bits; struct { Byte VIDEO0 :1; // video mode bits Byte VIDEO1 :1; Byte ORIENT0 :1; // orientation bits Byte ORIENT1 :1; Byte FREQ0 :1; // frequency bits Byte FREQ1 :1; Byte LED :1; // LED enable bit Byte :1; // unused } bit; struct { Byte mrgVIDEO :2; Byte mrgORIENT :2; Byte mrgFREQ :2; Byte :1; Byte :1; } mergedbits;} vconfig_union;#define VCONFIG vconfig.bits#define VCONFIG_VIDEO0 vconfig.bit.VIDEO0#define VCONFIG_VIDEO1 vconfig.bit.VIDEO1#define VCONFIG_ORIENT0 vconfig.bit.ORIENT0#define VCONFIG_ORIENT1 vconfig.bit.ORIENT1#define VCONFIG_FREQ0 vconfig.bit.FREQ0#define VCONFIG_FREQ1 vconfig.bit.FREQ1#define VCONFIG_LED vconfig.bit.LED#define VCONFIG_VIDEO vconfig.mergedbits.mrgVIDEO#define VCONFIG_ORIENT vconfig.mergedbits.mrgORIENT#define VCONFIG_FREQ vconfig.mergedbits.mrgFREQtypedef struct { Byte data[7]; vconfig_union vconfig; } mem_array;mem_array memory;unsigned char test;void main(void) { /* put your own code here */ memory.VCONFIG_VIDEO0 = 1; test = memory.data[7]; for(;;) {} /* wait forever */ /* please make sure that you never leave this function */}
52: memory.VCONFIG = 0x12; 0000 c612 [1] LDAB #18 0002 7b0000 [3] STAB memory:7 53: test = memory.data[7]; 0005 b60000 [3] LDAA memory:7 0008 7a0000 [3] STAA test
Becareful with the array as it doesn't seem to be checking the bounds.
byte memory[8]; // flash config bytes
irob wrote:
However, it seems that all my instances of VCONFIG will have to change to something like memory.vconfig. In the debugger, I'm seeing two entries for vconfig, both with separate segments in RAM. The second is an element of the memory structure.
extern volatile vconfig_union vconfig;
irob wrote:
Is there a way I should be restructuring my #define's so that my labels -- like VCONFIG -- call out the memory. vconfig structure elements? The #define obviously makes it more manageable.
#define VCONFIG memory.vconfig.bits#define VCONFIG_VIDEO0 memory.vconfig.bit.VIDEO0#define VCONFIG_VIDEO1 memory.vconfig.bit.VIDEO1#define VCONFIG_ORIENT0 memory.vconfig.bit.ORIENT0#define VCONFIG_ORIENT1 memory.vconfig.bit.ORIENT1#define VCONFIG_FREQ0 memory.vconfig.bit.FREQ0#define VCONFIG_FREQ1 memory.vconfig.bit.FREQ1#define VCONFIG_LED memory.vconfig.bit.LED#define VCONFIG_VIDEO memory.vconfig.mergedbits.mrgVIDEO#define VCONFIG_ORIENT memory.vconfig.mergedbits.mrgORIENT#define VCONFIG_FREQ memory.vconfig.mergedbits.mrgFREQ
allawtterb wrote:That being said, I don't like the implementation very much. The overlaying of memory.data[7] and memory.vconfig is only because the compiler is letting you access an array out of it's bounds.