EE 308 - LAB 4

Final version for 2000


Parallel Ports and Subroutines

Introduction

In this week's lab you will write an assembly-language program to display various patterns on the LEDs of your breadboard. You will use the HC12's Port A as an output port to display the LED patterns, and Port B as an input port to decide which pattern to display.

Ports A and B are the easiest HC12 parallel ports to understand and use. For this week's lab, you will create programs to write to Port A, and read from Port B. You will use information from switches connected to Port B to control the pattern you output on Port A. You will test your programs by connecting Port A to 8 LEDs, and vary the Port A output by changing the switch settings connected to Port B.

Pre-Lab

Write a program to set up Port A as an 8-bit output port, and to implement (i) a binary up counter, (ii) a rotating bit, (iii) a flasher, and (iv) a turn signal on Port A. Samples from the sequences that you should generate are shown in Fig. 1. You will use eight LEDs to see the Port A output. Include an appropriate delay between changing the LED pattern so that you can easily and comfortably see them flash. Use a subroutine to implement the delay. Also, set up Port B as an 8-bit input port, and use Port B bits 1 and 0 to control which of the Port A functions are performed as shown in Fig. 2.

Write the program before coming to lab. Be sure to write the program using structured, easy-to-read code. Be mindful of the delay requirement before changing the display or reading the Port B pins to determine if you should switch to a new function. When you switch between functions, the new function should start up where it ended when it was last activated, so set aside variables to save the states of the various patterns.

Here are the patterns which your program should implement:

  

  1. A binary up counter:

  2. A rotating bit:

  3. A flasher:

  4. A Ford Thunderbird style turn signal that alternates between right and left:


Figure 1: Samples of the functions to be performed using Port B as an output.

  
PB 1 PB 0 Port A Function
0 0 Up Counter
0 1 Rotating Bit
1 0 Flasher
1 1 Turn Signal

Figure 2: Port B inputs to control the Port A functions.


The Lab

1.
Run your program on the ZAP simulator. Note that you will want to reduce the delay considerably before doing this.

2.
Set a breakpoint at the first line of your delay subroutine. When the breakpoint is reached, check the value of the stack pointer, and the data on the stack. Make sure you understand what these mean.

3.
Wire up Port A to 8 LEDs, and Port B bits 1 and 0 to a connection that can be switched between 5 volts and ground. Use the DIP switches on your breadboard to connect to the Port B pins. Show the lab instructor that your program works as specified in Figures 1 and 2.

Begin by wiring up the Port B pins to switches, and make sure you can read the state of the switches. (Note that you can simulate the input on Port B by changing the value of address 0x0001 to the desired bit pattern.) After you are sure you can read the state of the switches on Port B, start working on the part of the program which implements the various bit patterns. Start with one function only, say, the one to increment Port A. Begin by testing it with no delay subroutine on the simulator. When it works there, put it onto your EVBU, with the delay routine. Once you have this working. Once this works, start working on your next functions.

Note that the easiest way to implement the turn signal function is to make a table containing the various patterns and use an index into the array to decide what pattern to display.

4.
Load the program into your HC12. Make sure that the program works. Have your lab instructor or TA verify the program operation.

5.
Put your program in the EEPROM at address 0x0D00. Note that you will want the array which stores the turn signal patterns into the EEPROM (so the array will not disappear when you turn off power). You will want variables which will change as the program is executed to be placed in RAM.



Bill Rison
2000-02-09