User Tools

Site Tools


Lab 2: Writing Driver Software for the Slide Switches and Push Buttons


  1. Gain practice and experience with the Xilinx SDK.
  2. Gain experience with commercial documentation.
  3. Understand how the GPIO IP block functions and write low-level code to communicate with it (instead of using the functions provided by xgpio.h).
  4. Learn how to write low-level software to interface with buttons and switches.
  5. Practice applying the class coding standard.
  6. Write reusable code that you may use in later labs.
  7. Write test code that demonstrates the correctness of your implementation and that demonstrates how to use the button/switch software driver that you wrote.
  8. Gain additional practice with the graphic library and the LCD.

New Terminology


In this lab you will write and test driver software for the slide switches and push buttons that are on the 330 board. The schematic for these switches and push-buttons is shown on Page 22 of the ZYBO reference manual. The switches and push-buttons are items 9 and 13, respectively, shown in the photo of the Zybo board (Page 3 of the Zybo reference manual and duplicated below).

The schematic for the switches is also shown below (Page 22 of Zybo reference manual).

Question: What is the logic value of the pin attached to the push-button when the button is pushed? When it is released?


Programming Stack for Lab 2

We often refer to “stacks” when we talk about computing systems. A stack is a conceptual term that refers to multiple layers of software stacked one upon the other. See Programming Stack for more information on how this terminology applies to this lab.

GPIO and Register-Based Access

When using programmable processors such as microprocessors, etc., we access low-level hardware via registers. See the GPIO and Registers page to understand how you will access the registers in the GPIO (General Purpose Input/Output) module.


Make sure to read the resources page as it provides helpful and necessary information for this lab.


  1. You must create two files: buttons.c, switches.c. The “buttons” files will contain the code necessary to access the push-buttons while the “switches” will contain the code necessary to access the slide switches.
  2. You must use the provided .h files as is. No modifications are necessary or allowed.
  3. You must follow the coding standards as described on the class web page.
  4. You must implement the required functions for the buttons and switches drivers (see below).
  5. switches_runTest() will illuminate the LEDs on the ZYBO board above the slide switches (include “supportFiles/leds.h” to access the necessary LED functions). switch_runTest() will run until all of the slide switches are slid up at which point it will terminate.
  6. buttons_runTest() will use the LCD display to demonstrate that the buttons are working (see the video referenced below). buttons_runTest() will run until all of the push-buttons are pressed simultaneously, similar to switches. When the 4 push-buttons are simultaneously pressed, this function returns.
  7. Do not use the XGpio_SetDataDirection(), XGpio_DiscreteWrite(), XGPIO_DiscreteRead() functions. Use the low-level access as was shown above. In other words, don't use xgpio.h. I want you to learn how low-level access works by writing your own software.
  8. Write helper functions (not included in the .h file) for accessing the GPIO registers:
    • buttons_readGpioRegister(int32_t offset),
    • buttons_writeGpioRegister(int32_t offset, int32_t value),
    • switches_readGpioRegister(int32_t offset),
    • switches_writeGpioRegister(int32_t offset, int32_t value).
  9. You must define isr_function() in your main.c file just as it was defined in the main.c file in the helloWorld lab.
  10. Watch the provided videos to see what your test functions should look like once implemented (see below). For the button-test note that the rectangles that are drawn on the display must not flicker during the test.

Source Code

Source files for buttons.h and switches.h.

Pass-Off Demonstration Videos

These videos will demonstrate how your programs should operate when you attempt to pass them off.

Pass Off

Note: The TAs cannot pass off any project until they review the code and make sure that it has no more than 5 coding-standard errors.

Look at the two Lab2 videos on the youtube channel to see what runTest() should look like for but buttons and switches. To pass off the lab, demonstrate both of your runTest() functions for one of the TAs. To execute the two runTest() functions, just write a simple main.c file as follows:

#include "switches.h"
#include "buttons.h"
int main() {

When one test terminates, the next will start. Simple enough.


The grading breakdown for this lab is a follows:

  1. 30% Code quality and adherence to the coding standard. You are allowed 10 freebies for this lab.
  2. 70% Pass off. If your code works well and shows no bugs, you should get the full 70%.

Submitting Source Code

Follow this procedure to submit your source code to learning-suite.

lab_2.txt · Last modified: 2019/05/15 16:20 by hutch