

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Homework Assignment #3 Due Monday, May 18
Homework Programming Objective: Software controlled switch/line debounce and microcontroller handshaking.
Part 1: You are to design the circuitry and software for writing to a tri-state bus that could be used when communicating with another microcontroller when the other microcontroller is the “bus master”. In this operation, the bus master will provide a handshaking signal, H1, (Port M pin4). When H1 is high, no action is taken, when H1 transitions from high-to-low (1=> 0) it may by due to a switch bounce. Therefore, after first observing the high-to-low transition, you must wait for 10 usec and recheck the signal. If it is still low, it is a request for data from your processor. If it is not still low, it was a glitch and should be ignored.
When a high-to-low has been accepted, you must in the following sequence (1) output an 8-bit word to Port T, (2) generate an ENABLEn signal (Port M pin0) that transitions from high-to- low, remains low for 60 usec and then transitions from low-to-high where it remains until the next H1 high-to-low cycle, and (3) generate an H2 signal (Port M pin1) that transitions from low-to-high 10 usec after the ENABLEn signal remains low and transitions from low-to-high 10 usec before the ENABLEn signal. The timing diagram for this sequence is shown in Figure 1.
ENABLEn
Glitch, not acted on
10 usec intervals
SW handshake test passes
Bus Port T Values
Figure 1. Desired system timing
For hardware, connect the Port T outputs to a ‘540 or ‘541 buffer as used in Lab 3 and 4, connect the ENABLEn signal to OE1n of ‘540 or ‘541, plus 10 kohm pull-up resistors on the output of the buffer (pulling the “bus” high when the ENABLEn signal is high), and use another ‘540 or ‘541 as a buffer for H2.
You should consider the Adapt9S12DP512 Board with the CPU E-clock set to 8MHz (one cycle time is approx. 125ns).
Homework try points:
(a) Write a software C function that is a 10 usec delay.
(b) Write a software code segment that monitors H1 (Port M pin4) reading it regularly in a loop while it remains high. When it sees a high-to-low transition, stop looping, wait 10 usec (call the function from part a) and read the bit again. If the value is one, return to the monitoring loop. If not, “continue”.
(c) Write a software code segment that makes ENABLEn (Port M pin0) transition from high-to- low and waits for 10 usec (calls the function from part a).
(d) Write a software code segment that makes H2 (Port M pin1) transition from high-to-low and waits for 40 usec (calls the function from part a) and then makes H2 transition from low-to-high..
(e) Write a software code segment that waits for 10 usec (calls the function from part a) and then makes ENABLEn (Port M pin0) transition from low-to-high.
(f) Combine the code segments into a program that performs the stated objective of Part 1. Turn in your assembled .lst file.
(g) Draw the hardware schematic for the defined system.
Part 2: Assume that your microcontroller is now the “bus master”. You must provide H1b as a handshake, making a high-to-low transition when you want to read data. When H2b transitions from high-to-low, wait 10 usec to make sure that it isn’t a glitch, and read the tri-state bus using Port J. After your done reading, have H1 transition from low-to-high.
Homework try points:
(a) Write a software code segment that makes H1b (Port M pin2) transition from high-to-low and monitors H2b (Port M pin5) reading it regularly in a loop while it remains high. When it transitions from high-to-low, stop looping, wait 10 usec (call the function from part a) and read the bit again. If the value is one, return to the monitoring loop. If not, “continue”.
(b) Write a software code segment that first reads Port J and then makes H1b transition from low-to-high.
(c) Combine the code segments into a program that performs the stated objective Part 2. Turn in your assembled .lst file.
(d) Provide a modified timing diagram that shows the timing for H1b instead of the H1 of Figure 1.
(e) Could you use the RTOS from Lab #2 and have each of the two programs written for Part 1 and Part 2 act as independent applications?