I am using c programming in PIC18F87K90 microcontroller. I am having a problem about creating a structure variable (with union within it) to have an easier access to multiple flags (most are 1-bit flags, but some are 2-bit or 3-bits).
The code below works well. I used simulator to check the address bytes of each member. The members of the structure inside the union are grouped in the same address byte, which I expect since the members have a total of 8-bits which should fit in 1-byte. I also check the addresses of: eeprom_flag.byte0, eeprom_flag.reset_time_byte... etc and they are in same address due to union usage. My problem is that I wanted to have two possible names for one of the 1-bit flag, which is eeprom_flag.output_time_bit. I wanted to have another name for it (but exactly same variable-bit, same address). I tried using union to do that (see commented lines below). However, doing that will break my code such that the members of the structure are no longer in same addresses. My goal to do addressing as seen in the uploaded image.
typedef struct
{
//buffer index 0
union
{
struct
{
uint8_t reset_time_bit:1;
// union
// {
uint8_t output_time_bit:1; //shared address
// uint8_t output2_time_bit:1;
// };
uint8_t count_mode_bit:3;
uint8_t input_mode_bit:1;
uint8_t count_speed_bit:2;
};
uint8_t byte0;
uint8_t reset_time_byte;
uint8_t output_time_byte;
uint8_t output2_time_byte;
uint8_t count_mode_byte;
uint8_t input_mode_byte;
uint8_t count_speed_byte;
};
} eeprom_flag_t;
extern volatile eeprom_flag_t eeprom_flag;