union _word { uint16_t word; uint8_t byte[2]; } wrd; wrd.byte[0] = data; wrd.byte[1] = reg; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=67601 typedef union { volatile unsigned char flinps; struct { unsigned char b0 : 1; unsigned char b1 : 1; unsigned char menubtileft : 1; unsigned char menubtimiddle : 1; unsigned char menubtiright : 1; unsigned char b5 : 1; unsigned char b6 : 1; unsigned char b7 : 1; }; } flinps_union_t; typedef union { volatile unsigned char buttons; struct { unsigned char b0 : 1; unsigned char b1 : 1; unsigned char menubtbleft : 1; unsigned char menubtbmiddle : 1; unsigned char menubtbright : 1; unsigned char b5 : 1; unsigned char b6 : 1; unsigned char b7 : 1; }; } buttons_union_t; typdef struct { flinps_union_t flinps; buttons_union_t buttons; unsigned char buttprsd; unsigned char fdsmsm; unsigned char tmpinps; } mydata_struct_t; mydata_struct_t mydata; int main(void) { mydata.flinps.menubtileft = 1; mydata.buttons.menubtbright = 0; mydata.buttprsd = 11; mydata.fdsmsm = 22; mydata.tmpinps = 33; } ------------------------------------------------------------------------------- Как брать отдельные байты от слова? http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=20709&start=0 A UNION is the most elegant solution and designed to perform just this task. Code: union u_type //Setup a Union { unsigned int IntVar; unsigned char Bytes[2]; } temp; //Assign a var name to the Union void main(void) { temp.IntVar=65535; //Assign a value to the Int var of the Union HighByte=temp.Bytes[1]; //Get the High Byte (255) LowByte=temp.Bytes[0]; //Get the Low Byte (255) } ---------- into a series of char (8-bit) pointers. Example: Code: unsigned char low_byte; unsigned char high_byte; unsigned int the_value; ... the_value = 1234; low_byte = * ((unsigned char *)&the_value); high_byte = * ((unsigned char *)((&the_value)+1)); or a char-sized pointer could be used the same way. [I'd probably use the pointer method for repetitive uses within an app and/or many-byte variables.] Code: unsigned char low_byte; unsigned char high_byte; unsigned int the_value; unsigned char *the_ptr; ... the_value = 1234; the_ptr = * ((unsigned char *)&the_value); low_byte = *the_ptr; the_ptr++; high_byte = *the_ptr; ---------- the bset way: it only compile in ONe line asm code ! Code: #define LowB(x) (*((unsigned char*) &(##x)+1)) #define HighB(x) (*((unsigned char*) &(##x)+0)) for ex for low byte use LowB(x) только тут наверное младший байт без смещение (лежит первым), а старший байт -- +1. И тогда это совпадёт с предыдущим примером.