A Bluetooth-enabled device transmits two separate bytes of data once per second
ID: 2083116 • Letter: A
Question
A Bluetooth-enabled device transmits two separate bytes of data once per second to a Bluetooth-enabled microcontroller. The two bytes contain the 12 bits (a_0 to a_11) of a variable, a bit 's' and 3 unused bits as shown in Figure 2. When the bit 's' is 0, it indicates that the transmitted data is wrong. Assuming that a 'C' code has two variables B1 and B2 declared as unsigned char and are used to hold the two bytes, byte 1 and byte 2, received by the microcontroller respectively. Add lines to the 'C' code to continuously: check if the received data is correct (wait if it is not correct); and if the received data is correct, assign the 12 bits to a variable using one statement only. The variable needs to be declared first using the appropriate data type.Explanation / Answer
struct bit_field
{
unsigned x: 12; // structure to declare a 12 bit number
};
main(){
unsigned char B1,B2;
bit_field n;
while(1){ //running an infinte loop of samples
while((B1 & 0x01)==0x00); //wait here until the data becomes valid(last bit is not equal to 0)
n.x=((B2<<4)&(0xFF0))|((B1>>4)&(0x00F)); //to make the 12 bit number left shift B2 and right Shift B1 and add them to a single 12 bit number
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.