Digital I/O: Launchpad Peripherals

The Launchpad has four notable peripherals: a standard LED, an RGB LED, and two push buttons (located on the sides of the Launchpad). The two buttons are inputs, whereas the LEDs are outputs. You can find the circuit diagram for these peripherals in the Launchpad user manual, which is also shown below. 

Under the User LEDs block, you may notice that there seem to be four connections rather than just two for the LEDs. The top one is isolated from the other connections, as it is used by LED1, the standard LED that can only be either be off or on (emitting a red light). The other three connections each control a specific color on the RGB LED, which is LED2. These colors are red, green, and blue. By turning on or off the individual colors, LED2 can produce a blend of the different colors.

In order to use these LEDs, note that each of the wires have labels on them, positioned all the way to the left. These labels show which ports and pins each of the LED components are connected to. Thus, the diagram shows that LED1 is connected to P1.0, or Port 1, Pin 0. For LED2, its red light is connected to P2.0 (Port 2, Pin 0), its green light is connected to P2.1 (Port 2, Pin 1), and its blue light is connected to P2.2 (Port 2, Pin 2). 

The push-buttons, by virtue of being inputs, are not as straightforward to enable. Not only do we have to set the direction register(s) to the appropriate value, but we have to consider whether the inputs need pull-up/pull-down resistors. Take a look at the User Buttons block in Figure 29. Are there any resistors in the circuit schematic? No. Therefore, the buttons will need pull-up or pull-down resistors. Which type will they need? Let’s take the top button, S2. The leftmost point of the wire is the input to the microcontroller. If you push down S2, the microcontroller now has a connection to ground, thus the button can input logic level 0 without additional help. What if S2 is not pushed? The microcontroller is now connected to an open circuit, thus a floating voltage, which doesn’t have a corresponding logic level. Thus, this button is unable to reliably produce logic level 1, so this floating voltage needs to be “pulled up” to a 1. Hence, we will need a pull-up resistor for S2. Following this same procedure for S1 leads to the same conclusion: S1 also needs a pull-up resistor.

Looking at the mappings for each button, S1 is mapped to P1.1, and S2 is mapped to P1.4. Both buttons belong to the same port, so we can configure both as inputs at the same time, keeping note that S1 uses Bit 1 and S2 uses Bit 4 of the port registers. Referring to Table 12-1, in order to configure these inputs with pull-up resistors, P1DIR.x needs to be 0, P1REN.x needs to be 1, and P1OUT.x needs to be 1 (where x is the pin of the corresponding button). With bitmasks for Bits 1 and 4 (BIT1 and BIT4, respectively), we can bitwise AND P1DIR with the complements of those bitmasks (P1DIR = P1DIR & ~(BIT1 | BIT4)) to configure them as inputs. Then, to enable the resistor, we can bitwise OR P1REN with the bitmasks (P1REN = P1REN | (BIT1 | BIT4)). Finally, to designate the resistor as a pull-up resistor, we can bitwise OR P1OUT with the bitmasks (P1OUT = P1OUT | (BIT1 | BIT4)). 

The below figure summarizes the register contents for pin 0 and pin1 of the port 1 that correspond to LED1 and Button 1 of the Launchpad, respectively. Cross (X) represents Don't Care, while Data represents either the input or output data related to that pin. For the LED, Data = 1 means LED is on, and Data = 0 means the LED is off. For the Button, Data = 0, means the Button is pressed, and Data = 1 means the buttons is released.