ECE2049: Homework 3 2. In this example, two switches and a blue LED are connecte
ID: 2293432 • Letter: E
Question
ECE2049: Homework 3 2. In this example, two switches and a blue LED are connected to an MSP430F5529 running the code shown below. Answer the following questions about the configuration. void configure io (void) P2.5 P2.4 void main (void) MSP430 char val, configure io while (1) P2.0 Are P2.4 and P2.5 being used as inputs or outputs? What logic level (0 or 1) will result when a switch is closed? a. b. What logic level (0 or 1) turns on the LED? This configuration example code does not modify the P2REN register. Does it need to be configured in this case? Explain why or why not. c. d. In the example main0, what happens to the LED (on or off) if val 0x74? What happens if val - 0xD7?Explanation / Answer
Answer :- a) P2.4 and P2.5 are being used as input pins here. When switch is closed the pins are connected to ground, thus a logic level 0 will result.
Answer :- b) To make the LED on, LED must be in forward biased. So a logic 1 from pin P2.0 will make LED on.
Answer :- c) P2REN is used to enable or disable the pull-up and pull-down resistor for input pins. Here we have already used resistors for the input pins P2.4 and P2.5 with power supply, so no need to enable using P2REN.
Pull-up or pull-down resistors are used to define that what input should pin take when nothing has been given. Like here when switch is not closed the external pull-up resistor setting makes pin at logic 1 by default.
Answer :- d) LED will glow.
When 0x74 is the value of val, then s = ((0x74 & 0x60) >> 5) = (0x60 >> 5) = 0x03. So s = 3 hence else part will execute. In this PIN2.0 = ( PIN2.0 | 0x01 ) = 0x01, so LED will glow.
When val = 0xD7 then s = 0x02. Hence LED will glow. LED will be in OFF mode only is s = 0x01.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.