Lab 3
Lab 3b – Reading a Push Button
GPIO Input Worksheet
1. What three DriverLib functions can setup a GPIO pin for input?
Hint, one place to look would be the MSP430 DriverLib Users Guide found in the
MSP430ware folder: \MSP430ware_1_60_01_11\driverlib\doc\MSP430F5xx_6xx\
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
2. What can happen to an input pin that isn’t tied high or low?
_________________________________________________________________________
_________________________________________________________________________
3. Assuming you need a pull-up resistor for a GPIO input, write the line of code required
to setup
pin P2.1 for input:
_____________________________________________________________________;
4. Complete the following code to read pin P2.1:
volatile unsigned short usiButton1 = 0;
while(1) {
// Read push-button pin (SW1)
usiButton1 = ______________________________________________________;
if ( usiButton1 == GPIO_INPUT_PIN_LOW ) {
// If button is down, turn on LED
GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN0 );
}
else {
// Otherwise, if button is up, turn off LED
GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 );
} }
5. In embedded systems, what is the name given to the way in which we are reading the
button?
(Hint – it’s not an interrupt.)
_________________________________________________________________________
Check your answers against ours … see the Chapter 3 Appendix.
MSP430 Workshop - Using GPIO with MSP430ware 3 - 29