Final version for 2001
Parallel Ports and Subroutines
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.
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:
|PB 1||PB 0||Port A Function|
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.