Hello, and welcome to the forum.
Since the 24-bit data is arranged in little endian format, it is probably simplest to treat the problem as three separate additions of single byte values, within three byte arrays. Had the data arrangement been big endian (native to the MCU), a different approach might be adopted.
The following code snippet provides a function uses this method. For simplicity, the snippet does not provide 24-bit overflow handling. This may need to be added.
void add24( char *p1, char *p2, char *pr){ unsigned int i, r, c = 0; for (i = 0; i < 3; i++) { r = p1[i] + p2[i] + c; c = r >> 8; pr[i] = (char)(r & 0x00FF); }}
The function would be called in the following manner -
// Global variables - little endian 24-bit formatbyte var1[3] @ 0x3000 = { 0x45, 0x23, 0x01}; // byte var2[3] @ 0x3003 = { 0xAB, 0x89, 0x67};byte var3[3] @ 0x3006; ... add24( var1, var2, var3);
Regards,
Mac