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.
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:
|PB 1||PB 0||Port A Function|
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.