Laboratory Exercise #03 Button Input and Serial Communication Solution



You'll get a: . zip file solution : immediately, after Payment

Offer ends in


Rate this product

1 Introduction

In this laboratory exercise you will write, compile, execute, and demonstrate a program to sense the push buttons on the LM3S1968 board, generate a tone, and communicate over the serial port.

This laboratory builds on Lab #01 (Blinky) and Lab #02 (SpeakerBuzz). You should make a copy of your Task_Blinky/SpeakerBuzz project and work with the copy in this lab.

The program will: (1) monitor the five push buttons on the LM3S1968, (2) generate a (distinct) tone when a button is pushed and released, and (3) report the button press via the serial port. Your program should continue to blink the LED and write the current value of SysTickCount to the OLED display. You will write a report describing your measurements, analyses, and conclusions.

1.1 LM3S1968 Evaluation Board Switches Background

The LM3S1968 evaluation board has five switches that can be used for user input, these are named Select (SW2), Up (SW3), Down (SW4), Left (SW5), and Right (SW6). When a switch is pressed, the corresponding GPIO input signal is pulled to Ground, i.e. a 0 input to your program.

1.1.1 Switch Bounce

When a switch is pressed, it does not generate a clean signal. That is, the signal may change from 1 -> 0 -> 1 -> 0 -> 1 -> 0 before it settles at a 0 state. This is called switch bounce and is a characteristic of the switch mechanics. When the switch is released, it returns to a 1 state. Generally, there is no switch bounce when the switch is released. A typical GPIO signal might look like:

Your program must compensate for switch bounce.

EECS 388 Laboratory #3


Version E

The five switches on LM3S1968 evaluation board are shown in the following figure:

The figure is from: TI_Stellaris_LM3S1968_EvalBoard.pdf. The schematic shows the signals, e.g. RIGHT_SWn, are connected to ground when the switch is pressed. The GPIO port must provide a weak pull-up to bring the signal high when the switch is not pressed. The schematic shows that signals UP_SWn…SELECT_SWn are connected to PortG<3..7>, respectively. Therefore, you will have to program GPIO PortG appropriately to read the buttons.

2 Laboratory Exercises

2.1 Before Laboratory Period(s)

Before you come to lab you should do the following:

  1. Design your task and write pseudo-code describing your task. Submit your pseudo-code prior to your laboratory period according to your GTA’s instructions.

  1. Write your task using a text editor. Make sure your task is well organized, well formatted, and documented.

EECS 388 Laboratory #3


Version E

  1. Use the computers in the lab or computing commons to compile and debug your task.

  1. Bring a printed version of your task to your lab.

You may use parts of the task you have run in lab or other programs. However, if you use code from any other program, you must cite the source of that code in your report.

You may ask questions about the lab in lecture.

2.2 In Lab

  1. Show your lab instructor your printed listing of your task.

  1. Demonstrate your task to the lab instructor.

  1. Be prepared to answer questions about your task asked by your lab instructor.

2.3 Complete the Laboratory

Collect your measurements, logs, copies of your task in your directory, and clean up your lab bench. If you checked out a probe kit, make sure you return it to the EECS Shop immediately after you are finished in the lab.

Instructions for writing your report will be provided by your lab instructor.

3 Program Description

Your task will implement the following general activities (along with LED Blink and

SysTickCount reporting to the OLED):

  1. Your task will monitor the five buttons on the evaluation board.

  1. Your task will generate a tone when the switch press is detected and when the switch is released.

  1. Your task will report the identity of the switch released via the serial communication port.

  1. You do not have to account for more than one switch pressed at the same time nor for rapid, less than 2 Seconds interval, pressing of the switches.

3.1 Button Monitoring and Tone Generation

  1. Your task will monitor the five buttons on the evaluation board. You shall check the button state once each 1 mS.

  1. When a button transition is detected, your task shall wait 10 mS to insure the button is actually pressed. This is the de-bounce period.

EECS 388 Laboratory #3


Version E

  1. When a button is pressed and switch bounce is compensated for, your program will emit a 440 Hz tone on the speaker for 0.2 Seconds.

  1. When a button is released, your program will emit a 440 Hz tone for 0.5 Seconds and report the event via the UART. The message shall state: “Button <x> released.\n.” Where <x> is the identity of the button, e.g. “UP,” “DOWN,” … or “SELECT.”

4 Program Structure

4.1 Button Monitor Setup

You program must configure GPIO PortG to read the five buttons. The buttons are connected to PortG<7..3>. The actions are:

  1. Enable PortG with SysCtlPeripheralEnable.

  1. Set PortG<7..3> pins to input with GPIOPinTypeGPIOInput() subroutine

from DriverLib.

  1. Set PortG<7..3> pins to weak pull-up with GPIOPadConfigSet. You do not have to set the drive current on these pins.

4.2 Button Monitor

Your program must:

  1. Read the state of the five buttons every 1 mS.

  1. If a button is released, go to step 6.

  1. If no button is pressed, exit.

  1. If a button is pressed, wait 10 mS.

  1. If the same button is pressed after 10mS, declare a button press and emit a 0.2 S tone at 440 Hz and exit.

  1. On release of a button, emit a 0.5 S tone at 440 Hz and send a message using the UART.

4.3 UART Setup

UART0 is connected through GPIO PortA. You will use an API known as UARTStdio. This API and associated *.h is in your program “Drivers” directory. A subroutine will be provided to you to carry out this initialization.

The actions to set up UART0 and send a short message are:


  • Enable UART0, to be used as a serial console.

SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOA );

EECS 388 Laboratory #3


Version E

SysCtlPeripheralEnable( SYSCTL_PERIPH_UART0 );

GPIOPinConfigure( GPIO_PA0_U0RX );

GPIOPinConfigure( GPIO_PA1_U0TX );




  • Initialize UARTStdio

UARTStdioConfig( 0, 115200, SysCtlClockGet() );

4.4 UART Use

To output strings to the PC using UARTStdio, you use the UARTprintf function. It is similar, but simpler, than the common printf function. An example is:

UARTprintf( “Button: %d\n”, ButtonIndex );

UARTprintf is documented in the UARTStdio.c file.

4.5 COM setup on the Windows PC

See Appendix A for setting up serial communications on Windows PC machines.