Assigned
Wednesday, Oct 10, 2018
Due
Tuesday, Oct 16, 2018 by 10:30pm
Submitting
Demonstrate each part of your lab before moving on to the next part. If you do not finish the lab during class time you can arrange a time to demonstrate the remaining parts during office hours. If you are unavailable for office hours you can email a video of your working implementation for the remaining parts of the lab.

## Overview

In this lab, you will use the protoboard’s switches to blink LEDs in two or more different patterns. Along the way, you will write assembly code to call functions, read input, isolate bit fields, and perform conditional execution.

Note that you are expected to produce nicely-aligned, well-commented assembly code. Code that does not meet these standards will not be checked off.

## Part A: Delaying With a Loop

Our first task is to write a program that will blink the LEDs slowly enough for us to see. We’ll control the LED on the microstick the same way we did in the previous lab, but we’ll add a pause by asking the PIC32 to loop for a while before changing the state of the LED. Specifically, we’re going to use a MIPS version of the following C procedure:

// Precondition: iterations > 0
void delayloop(int iterations) {
do {
iterations--;
} while (iterations != 0);
return;
}


Translate the above C procedure to MIPS assembly with pencil and paper. Make sure you follow all the MIPS calling conventions in your translated version. When you have completed your translation, have the instructor or a mentor sign off on this part of the lab.

Now that we have our delayloop procedure we can use it to make the LED on the microstick blink slowly enough when running at full speed. You will need to calculate the number of iterations your delayloop procedure should run to pause for about half a second, then call this procedure with the appropriate value of iterations.

First, you’ll need to launch MPLAB.

mplab_ide &


Create a new project named blinky (if the software complains about an invalid folder, you will need to reboot your machine); pay close attention to whether you have a PIC32MX110F016B or the compatible PIC32MX250F128B and select the appropriate chip number when you create your project. In your new project, create a file named blinky.S (note capitalization) and copy the following code:

  # blinky.S
# Written by Janet Davis, 13 October 2013
# Edited by Charlie Curtsinger, 9 October 2018

.set noreorder  # Avoid reordering instructions
.text           # Start generating instructions
.globl main     # The label should be globally known
.ent main       # The label marks an entry point

# Preprocessor defines for output port control
#define ON  0x1
#define OFF 0x0

# The beginning of the delayloop procedure.
# Signature: void delayloop(int interations)
delayloop:
##########################################
# Transfer your delayloop procedure here #
##########################################

# The main entry point for the program
main:
la   $s0, TRISA # Load the address mapped to the TRISA control register li$t0, 0
sw   $t0, 0($s0)  # Store the value 0 to all bits of the TRISA register,
# setting all bits of Port A as output
la   $s0, LATA # Load the address mapped to the LATA control register loop: li$t0, ON
sw   $t0, 0($s0)  # Write to LATA, turning the LED on

#####################################
# Call the delayloop procedure here #
#####################################

## Part D: A Second Switch

In the final part of this lab you will use a second switch to add additional control to the blinking LED. You will need to wire a second SPDT switch to RB7, connected to either VDD or VSS in the same way as the first switch. Once you have the second switch connected, implement one of the following features:

1. Use the two switches in combination to select four different blinking speeds.
2. Use the first switch to control the time the LED is on and the second to control the time the LED is off.
3. Wire up four LEDs to RA0, RA1, RA2, and RA3. Changing the switches should control which combinations of LEDs turn on and off together; there are many possibilities, so you are free to choose whatever scheme you like.

Have the instructor or a mentor sign off on your implementation once you have finished one of the above features.