Explorer 16 board will be used. Show all your work for evaluation.

Question 1.
a. Consider the following configuration codes. Based on the codes below, how PORTD has been configured. Also determine the status (ON/OFF) of the LEDs connected to PORTD as the diagram?

TRISD = 0xAA;
PORTD = 0xAA;
PORTDbits.RD0 = 1;
PORTDbits.RD6 = 1;

b. In the above diagram, determine the current flowing through each of the LED, if R = 220 ohm and VLED = 1.8 Volts?

c. If R7 = 0 ohm, what is the current that will flow through that line?

d. We want to connect a switch to pin 30 and a LED to pin 19 in the above diagram. Draw the circuit accordingly. Also write the configuration code.

1 answer

a) Based on the given configuration codes:
TRISD = 0xAA; means that the lower 8 bits of PORTD (RD0-RD7) are set as inputs (high impedance), while the upper 8 bits are set as outputs.
PORTD = 0xAA; sets all the bits of PORTD to the value 0xAA, which is 10101010 in binary.

Therefore, the configuration of PORTD is as follows:
- RD0 and RD1 are inputs
- RD2 and RD3 are outputs
- RD4 and RD5 are inputs
- RD6 and RD7 are outputs

The status of the LEDs connected to PORTD can be determined as follows:
- RD0 is an input, so it does not control an LED.
- RD2 is an output and set to 1, so the LED connected to RD2 is ON.
- RD6 is an output and set to 1, so the LED connected to RD6 is ON.

b) To determine the current flowing through each LED, we can use Ohm's law:
VLED = IR

Given:
R = 220 ohms
VLED = 1.8 Volts

For each LED connected to RD2 and RD6:
I = V/R
I = 1.8V / 220 ohms
I ≈ 0.00818 Amperes or 8.18 mA

Therefore, the current flowing through each LED is approximately 8.18 mA.

c) If R7 = 0 ohms, it means there is no resistor connected to the line controlling RD7. In this case, the LED connected to RD7 should not be used (or a current-limiting resistor must be added externally). Without a resistor, the current flowing through the LED can exceed its maximum rating, potentially damaging it.

d) To connect a switch to pin 30 and an LED to pin 19, the following circuit can be used:

________________
| |
| | |
| I/O Pin ----- R (220 ohms) ------ LED ----- GND
| 30 |

The configuration code for the switch connected to pin 30 would be:
TRISFbits.TRISF2 = 1; // Set pin 30 (RF2) as an input

The configuration code for the LED connected to pin 19 would be:
TRISEbits.TRISE6 = 0; // Set pin 19 (RE6) as an output
PORTEbits.RE6 = 0; // Set pin 19 (RE6) to turn off the LED initially