Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 2. Consider an 8-light lighting system that is controlled by an array of 8-bit registers. The first element of the array controls light #1,

Problem 2. Consider an 8-light lighting system that is controlled by an array of 8-bit registers. The first element of the array controls light #1, the second element of the array controls light #2, and so on. We call these registers Light Status Register or LSR. For each LSR, the bits control the light based on the below specification.

  • Bit 7-6: control the light intensity: 00 off, 01 low, 10 medium, 11 high.
  • Bit 5-4: control the color: blue 00, green 01, red 10, yellow 11.
  • Bit 3 controls whether the light flickers: 0 no flicker, 1 flicker.
  • Bit 2-0 are unused.

Examples:

  • If we write 0x0 to an LSR, it means that the corresponding light should be off.
  • If we write 0xFF to an LSR, it means that the corresponding light should be yellow with the highest intensity and it should flicker.
  • If we write 0x68 to an LSR, it means that the corresponding light should be low intensity red with flicker.

  1. Show the value of an LSR that programs a light with red color and low intensity without flicker. Show the value both in binary and hex. 3 points

  1. Translate what it means if the value of an LSR is 0xBF. 3 points

  1. Define the masks for three different parts of LSR. Use the following template: 6 points

#define INTENSITY_MASK

#define COLOR_MASK

#define FLICKER_MASK

  1. Use typedef and enum keywords to define three new types called COLOR, INTENSITY, and FLICKERING which enumerate different color, intensity, and flickering possibilities. 6 points

  1. Write a function that receives the value contained in an LSR and returns the intensity of that lamp. The function declaration and example is shown below. 10 points

// Example:extractIntensity(oxff) returns HIGH

INTENSITY extractIntensity(unsigned int LSR);

  1. Write a function that receives three integers representing lamp flickering status, color, and intensity and returns the LSR value that will create that light combination. Use 0s for unused bits in the LSR. The function declaration and example is shown below. 12 points

// Example:makeLSR(MED_INTENSITY, BLUE, NO_FLICKER) returns 0x80

unsigned int makeLSR(INTENSITY newIntensity, COLOR newColor, FLICKERING newFlickering);

  1. Write a snippet of code, part of the main function, that increases the intensity of all the lights by one step. If a light is off, it will be turned on with the lowest intensity. The lights with the highest intensity will remain unchanged. Do not modify settings for color or flickering. Assume LSR_ARRAY[0] is the LSR location of the first lamp and LSR_ARRAY[7]is the LSR location of the last lamp. 16 points

Hint: In a loop, you need to read LSRs one by one, change them and write them back to the same location.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions