Next, we will connect the two LEDs required by our project to the microcontroller. To determine the direction of LEDs, each case has a marking identifying whether the one end is the anode or cathode end. I have found that looking for the larger element in the LED is simpler. The larger element within the LED is always the anode tied to the ground circuit. Looking closely even at a tiny 1206 surface mount packaged diode, you can still see the larger element within the diode.
Figure 8.3
Figure 8.4 contains a reference schematic for the LED connections.
Figure 8.4
The diodes and the microcontroller need to be protected from excessive current as a diode is similar to a jumper wire when the current is flowing in the correct direction. Therefore, we will start by installing 220ohm resistors. Install the first resistor to PortB.0 which is located at pin 2 according to the pin reference diagram located in the microcontroller's data sheet and is shown in figure 8.5.
Figure 8.5
Connect the second 220 ohm resistor to PortB.1 located at pin 3.
Figure 8.6
Now the LEDs need to be connected between the resistors and the 5 volt positive power circuit. Insure the anode lead is connected to the resistor and the cathode is connected to the positive circuit. I chose a red LED and a green LED to illustrate the difference between LED1 and LED0. Install the first LED.
Figure 8.7
Follow with the second LED.
Figure 8.8
LED Circuit