After many years I started for fun to program in C again. Now I have an issue with the use of structures and unions.
The declaration:
typedef struct {
unsigned char SOAKTEMP;
unsigned char SOAKTIME;
unsigned char REFLOWTEMPERATURE;
unsigned char REFLOWTIME;
unsigned char BAKETEMP;
unsigned int BAKETIME;
unsigned char COOLDOWNTEMPERATURE;
unsigned char COOLDOWNTIME;
unsigned char KP;
unsigned char KI;
unsigned char KD;
unsigned char CYCLETIME;
}EEPROM_DEFAULTS;
The initialisation:
EEPROM_DEFAULTS EEPD = {
170, // SoakTemp
90, // SoakTime
220, // ReflowTemperature
30, // ReflowTime
80, // BakeTemp
7200, // BakeTime
60, // CooldownTemperature
0, // CooldownTime
11, // Kp
5, // Ki
1, // Kd
5 // cycleTime
};
To write and read this data into the EEPROM of the PIC16F18877 I need to split BAKETIME into a high and a low byte.
I have done this with a Union.
union{
unsigned int Baketime;
struct
{
unsigned char BakeTimeLowbyte;
unsigned char BaketimeHighbyte;
};
} BT;
It works but I do not like the way I have done this. I have tried in many ways to incorporate the union into the EEPROM_DEFAULTS typedef but without succes. So my knowledge runs short after so many years. Assistance would be nice.