Page 1 of 1

Consider the following microcontroller 8-bit peripheral register: Bit 7 6 5 4 3 2 1 Purpose flag speed complete channel

Posted: Thu May 05, 2022 1:31 pm
by answerhappygod
Consider The Following Microcontroller 8 Bit Peripheral Register Bit 7 6 5 4 3 2 1 Purpose Flag Speed Complete Channel 1
Consider The Following Microcontroller 8 Bit Peripheral Register Bit 7 6 5 4 3 2 1 Purpose Flag Speed Complete Channel 1 (28.96 KiB) Viewed 34 times
Consider the following microcontroller 8-bit peripheral register: Bit 7 6 5 4 3 2 1 Purpose flag speed complete channel (a) Using standard C language bit operators, write C code to read the complete and go bits (3rd and 6th) and if both of their values are '1' then set both speed bits (4th and 5th) to '1' without changing the other bits. Assume the register's address has been pre-defined as REGISTER. (b) What is a C union and how does it differ from a struct? Why is union potentially very dangerous when accessing it? (c) For this register, create a single data structure in C that allows this register to be viewed as an unsigned char or a set of bit fields. (d) Re-code part (a) of this question using the data structure defined in (c). (e) The code in (d) seems to be better than the original code in (a) in terms of clarity. However, sometimes the original code would be preferred over the struct/union code. Why?