Question

The bits of a 32-bit register at address 0x4B000020 are connected to 32 proximity detectors – eac...

The bits of a 32-bit register at address 0x4B000020 are connected to 32 proximity detectors – each bit will
be a ‘1’ if it’s corresponding detector is near a solid object. The bits of a 32-bit register at 0x4B001020 are
connected to 32 LEDs, and writing a ‘1’ to any bit will turn on a corresponding LED. Write a C function that
can be called to illuminate LEDs 7-0 whenever the corresponding proximity detectors 7-0 are detecting an
object (that is, only illuminate and LED if a corresponding detector is active). Do not change any other bits
in the LED register.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer :- The C function can be written as-

#define DETECTOR_ADDRESS 0x4B000020
#define LED_ADDRESS 0x4B001020

void led_control()
{
if (*DETECTOR_ADDRESS & 0x1)
*LED_ADDRESS |= 0x1; /* make LED 0 ON if detector 0 detects solid, other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFFFE; /* make LED 0 OFF if detector 0 does not detect any solid, other bits unaffected */

if (*DETECTOR_ADDRESS & 0x2)
*LED_ADDRESS |= 0x2; /* make LED 1 ON if detector 1 detects solid, other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFFFD; /* make LED 1 OFF if detector 1 does not detect any solid, other bits unaffected */

if (*DETECTOR_ADDRESS & 0x4)
*LED_ADDRESS |= 0x4; /* make LED 2 ON if detector 2 detects solid, other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFFFB; /* make LED 2 OFF if detector 2 does not detect any solid, other bits unaffected */

if (*DETECTOR_ADDRESS & 0x8)
*LED_ADDRESS |= 0x8; /* make LED 3 ON if detector 3 detects solid, other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFFF7; /* make LED 3 OFF if detector 3 does not detect any solid, other bits unaffected */

if (*DETECTOR_ADDRESS & 0x10)
*LED_ADDRESS |= 0x10; /* make LED 4 ON if detector 4 detects solid, other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFEF; /* make LED 4 OFF if detector 4 does not detect any solid, other bits unaffected */

if (*DETECTOR_ADDRESS & 0x20)
*LED_ADDRESS |= 0x20; /* make LED 5 ON if detector 5 detects solid, other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFFDF; /* make LED 5 OFF if detector 5 does not detect any solid, other bits unaffected */

if (*DETECTOR_ADDRESS & 0x40)
*LED_ADDRESS |= 0x40; /* make LED 6 ON if detector 6 detects solid, other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFFBF; /* make LED 6 OFF if detector 6 does not detect any solid, other bits unaffected */

if (*DETECTOR_ADDRESS & 0x80)
*LED_ADDRESS |= 0x80; /* make LED 7 ON if detector 7 detects solid, other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFF7F; /* make LED 7 OFF if detector 7 does not detect any solid, other bits unaffected */

} /* end of the function */

NOTE :- The function must be called in a loop.

Add a comment
Know the answer?
Add Answer to:
The bits of a 32-bit register at address 0x4B000020 are connected to 32 proximity detectors – eac...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT