EE 308 - LAB 5

Parallel Ports and Subroutines

Introduction

In this week's lab you will write a 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 the Port B input to control the Port A output. You will test your programs by connecting Port A to 8 LEDs, and vary the Port A output by changing Port B inputs between to 5 volts and ground.

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 binary down counter, (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 binary down counter:

  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 Down Counter
1 0 Flasher
1 1 Turn Signal

Figure 2: Port B inputs to control the Port A 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.

The Lab

1.
Run your program on the ZAP simulator. Note that you will want to reduce the delay considerably before doing this. In the {\tt ZAP} simulator you can simulate the input on Port B by changing the value of address 0x0001 to the desired bit pattern.

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 with pull-up resistors on your breadboard to connect to the Port B pins.

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). To do this, include the table definition in the CODE section of your program, not in the DATA section. You will want variables which will change as the program is executed to be placed in RAM, so these should be in the DATA section.



Bill Rison, <rison@ee.nmt.edu >
Thu Feb 11 1999

© 1999, New Mexico Tech