CE-2800 Embedded Systems Software
Lab 4: Bouncing Light Revisited
Objectives
- Become familiar with assembly language program design and instructions
- Use assembly language branch instructions to implement conditional logic
- Use assembly language instructions to implement subroutines and
subroutine calls
- Use assembly language instructions to manipulate the Stack
- Become familiar with reading input from a Digital I/O port.
Assignment
In this lab, you will modify the "bouncing light" program from Lab 3
such that the behavior of the LEDs is affected by the position of the on-board
switches labeled SW1, SW2, INT0, and INT1. Specifically, your program must:
- Begin by lighting a single LED - specifically, LED 0. The position of the LED should not change initially.
- When SW1 is pressed, the LEDs should sweep to the left
continuously - as long as the switch is pressed. The delay between
successive LEDs should be the same as it was in Lab 3. After the sweep moves
all the way to the left (to LED 7), the sweep should repeat from LED 0.
If the switch is released, the LED sweep should stop. The sweep may stop in
the middle of a sweep (for instance, on LED 4) - it should not continue to
the end.
- When SW2 is pressed, the LEDs should sweep to the right
continuously - as long as the switch is pressed. After the sweep moves all the
way to the right (to LED 0), the sweep should repeat from LED 7. If the key is
released, the LED sweep should stop. The sweep may stop in the middle of a
sweep. The same delay between successive LEDs should be used.
- When both INT0 and INT1 are pressed at the same time, the
currently "on" LED should blink.
- The behavior when pressing any other combination of switches (e.g. SW1
and SW2) simultaneously is up to you. It is acceptable to make the program
act like no switches at all are pressed in these cases.
Design constraints:
- You must make use of a subroutine for the delay loop used for both left
and right sweeping. Use your delay subroutine from the previous lab.
- You must make use of subroutines for the right and left sweep
loops. Name them sweep_right and sweep_left.
- You must make use of a subroutine for the blinking. Name it
blink_current_led. Every time it is called, it should toggle the state
of the current LED - that is, if that LED is on, calling this subroutine
should turn it off (and vice versa).
- The sweep direction or blinking of the LED should change immediately after the state
of the switches changes. This means that the switches have to be checked after
each output / before each left/right shift or blink.
- Use the same design/naming techniques as your used previously: assign
meaningful names to Registers, labels, and constant symbols.
- EVERY subroutine must have the following format:
;****************************************************************************************************************
;subroutine sweep_right
; This subroutine <explanation follows>
sweep_right:
<register save to stack>
<code>
<register restore from stack>
ret
;****************************************************************************************************************
That is: every subroutine should be CLEARLY visible and explicitly indicated
via comments that it is a subroutine. Every subroutine must save the
contents of every register it modifies at the beginning of the <code> and
restore the contents before the RET instruction - via pushing and popping
the registers' values to and from the stack. This is needed in case the
program calling the subroutine is using those registers' values for another
purpose. (think about what trouble would be caused if modifying a local
variable in a Java method caused other variables with that same name in
other methods to change as well - chaos!).
Also: NEVER enter any code in a subroutine EXCEPT via rcall (i.e. NEVER rjmp
into the middle of a subroutine), and NEVER exit a subroutine except via ret
(i.e. NEVER rjmp out of the middle of a subroutine). Think of the asterisks
as walls around the subroutine - the only way over the walls is via rcall
and ret.
Hints:
- While the LEDs are hard-wired to PORTB, the switches SW1, SW2,
INT0, andn INT1 are hard-wired to PORTD: SW1 is hard-wired to pin 0,
while SW2 is wired to pin 1, INT0 to pin 2, and INT1 to pin 3.
You'll have to configure PORTB as an output port (as you have previously),
while configuring the pins of PORTD (those connected to the switches) as input. Look back at the
program from Lab 1 for an example of how to read the inputs - you actually
read inputs from PIND rather than PORTD.
- Switches SW1, SW2, INT0, and INT1 are wired such that they ground
their respective pins, driving the voltage at that pin to 0v when the
switches are pressed. Thus, when a switch is pressed, the logical value of
the corresponding pin is 0. The logical value returns to 1 when then switch
is released, provided that you have enabled the "pull-up" circuitry
in the code that initialized the pins for digital input (refer to the
lecture material). If you don't enable the pull-up circuitry, the voltage on
the pins will "float" somewhat randomly.
- You
should be able to call the same delay subroutine from within either left
sweep, right sweep, or blink subroutines.
- The left and right sweep subroutines are trivial - maybe 5 or 6 lines of
code.
- Develop and debug
your program in AVRStudio first (its' easier that way). To simulate an input
switch in the I/O view, select the bit in PIND corresponding to the input
the switch would set.
- You may find the instructions SBIC and SBIS convenient for
programming this lab, but you're not required to use them.
Demonstration
You must demonstrate your working program on your board before
the submission date.
Lab Submission (due 11:00pm, Tuesday, January 10, 2012)
For your submission, you need only supply your working, fully commented
Lab4.asm file.
Upload your submission through
Blackboard (assignment "Lab 4").
Be sure to keep copies of all your files, in case something gets lost.
Grading
Your lab grade will be determined by the following
factors:
Program - comments and formatting are important
aspects of assembly language programming! And it has to work correctly.
Timeliness of
submission as stated in the
course policies.