Lab 3 - Input, Output, Stacks and Subroutines
 
In this lab we will focus on how to generate input and output for the hcs12 and how to use subroutines. We will also learn a little about the stack. Understanding these concepts is essential to developing programs and is especially important for working with interrupts in a later lab.
 
In this three week lab, we will create a program (from scratch) that reads all four push-button port H switches and depending on which switch is pressed, will increment or decrement a number, which will be display in signed binary on the 8 port B LEDs.  
 
1-Prelab: Lab background
 
To hand in for your pre-lab, write a short program that will swap the values of the X and Y registers. Initialize these registers with the values X=$1234 and Y=$5678. Use the PULX and PULY instructions. Your program should be similar to "swap.abs.s1" in the stacks section, except that we are now dealing with 16 bit values rather than 8 bit values.
 
 
2-Tutorials
 
Review the concept of stacks on the hcs12.
 
Read and do the I/O Subroutine Tutorial. Make sure you are able to get the program run and to light the LEDs correctly. Double check that the switches work as expected.
 
 
3 - Program
 
   1. Following the steps outlined in the stationery tutorial above, create a new project called "lab3" from the ee3176 stationery.
 
   2. In the "Linker for HCS12" target panel settings, choose "Absolute, single file assembly project" and name it "lab3.abs". We have set up the project so that your executable s1 record that we load into the Dragon12 will be called "lab3.abs.s1".
 
   3. In the Project Files windows, open (double click) the file "labx_hcs12.asm" and then Save As "lab3.asm".
 
   4. Open the assembly file "lab3.asm" that you just created, and copy in the source code from the I/O Subroutine tutorial demo we just did. Change the header comments, etc. to reflect your name, the name of the program, date, etc. This program will serve as a "base" program that you will modify in the next step.
 
   5. There are two deadlines for this 3 week lab assignment:  the intermediate and final.   The intermediate will be due in the second week of the lab 3 by the end of your assigned lab section.  The final deadline is by the end of the third week.
 
For the first intermediate turn-in, you must demonstrate to the TA that you have basic code running that changes the Port B LEDs based on asserting each push button of Port H.    Start by copying code from the tutorial into your “lab3.asm” file.   This code will be the basis for your final lab 3 program.
 
For the final turn-in, you must demonstrate a complete program which fulfills these requirements:
  1.  The program should include an endless loop “polling” for the assertion of buttons on Port H.
  2.  Any button assertion of buttons 2, 3 or 4 should result in the execution of the update subroutine adding the value contained in register A to the value displayed on the port B LEDS.   This should be 1 for button 2, -1 for button 3, and 4 for button 4.  Failure to use a single subroutine for these three buttons will result in a failing grade.
  3.  Button 5 should result in the port B LEDs being cleared and does not require a subroutine.
  4.  The 8 bit result should be displayed on the 8 Port B LEDs.   The number should be considered signed and overflow should not be considered.
 
   6. Assemble the program, load it into the Dragon12 using the DBug12 "load" command, and then run the program using "g 1000" under DBug12. Once the program assembles and runs OK, do your check out with the TA.

4-Bonus Features
 
1 point bonus on final grade if entire lab is turned in during week 2.
 
1 point bonus on final grade if the unused dip switches are used to select the unsigned number used for incrementing in the case of button 4 and also if the number “pegs” when it hits the min or max values (i.e. won’t go higher than 127 or lower than -128 but will return).
 
Please remember that when you get a B with an 89, a C with a 79 or a D with a 69 and ask for me to raise your grade at the end of the semester, I’m going to check if you did this extra credit.
 
5 -What to Hand In
 
First week turn-in - Turn in the pre-lab exercise to the TA.
 
Second week turn-in - Demonstrate that the basic switch checking loop by changing the Port B LEDs to a unique value after the pressing of buttons 2, 3, 4, and 5 on port H.
 
Third week turn-in - Demonstrate complete functionality as described above.
 
At the subsequent lab, hand in the commented code from your program. Remember to include your: (1) name; (2) date; (3) class (eg, UTEP EE3176);(4) the name of the program (eg, "lab3.asm"); and (5) what the program does. In addition, there should be comments throughout your program that describe what the main sections of code do.
 
Also email your *.asm file and your s record file to ee3376@ece.utep.edu.  Only email the two files together in one email please.  Nothing more.  Zero credit for lab if this isn’t done.  Lab will be considered late if this email comes after the deadline.
 
 
EE3176 Lab 3