Hardware Reference
In-Depth Information
8.13 Exercises
Assume that the E-clock frequency of the HCS12 is 24 MHz for the following questions un-
less it is specified otherwise:
E8.1 Write a program to confi gure all Port T pins to be used in capturing event arrival times.
Use the interrupt-driven approach. Stay in a wait loop after completing the confi guration. Exit
the wait loop when all eight channels have arrived. Store the arrival times in memory locations
starting from $1000.
E8.2 Use the input-capture channel 1 to measure the duty cycle of a signal. Write an assembly
and a C program (in a subroutine format) to do the measurement.
E8.3 Assume that two signals having the same frequency are connected to the pins PT1 and
PT0. Write an assembly and a C program to measure their phase difference.
E8.4 Write an assembly and a C program to generate a 2-kHz, 70 percent duty cycle waveform
from the PT6 pin.
E8.5 Write an assembly and a C program to generate a 4-kHz, 80 percent duty cycle waveform
from the PT5 pin.
E8.6 Write a subroutine that can generate a time delay from 1 to 100 s using the modulus down
counter. The number of seconds is passed to the subroutine in accumulator A.
E8.7 What would be the output frequency of the PT0 signal generated by the following program
segment?
clr
PTT
movb
#$01,DDRT
bset
TIOS,$81
movb
#$01,OC7M
movb
#$01,OC7D
movb
#$90,TSCR1
movb
#$02,TCTL2
movb
#$0,TIE
movb
#$08,TSCR2
ldd
#$0
std
TC0
ldd
#$1
std
TC7
E8.8 Write a program to generate a 25-Hz digital waveform with a 50 percent duty cycle on the PT0
pin as long as the voltage level on the PP7 pin is high. Your program should consist of two parts:
1. Entry test. As long as the PP7 pin is low, it stays in this loop.
2. Waveform generation body. This part generates a pulse with 20 ms high time and
20 ms low time, and at the end of a period tests the PP7 signal. If PP7 is still high, it
generates the next pulse. Otherwise, it jumps to entry test .
E8.9 Write a program to wait for an event (rising edge) to arrive at the PT0 pin. After that, the
program will wait for 100 ms and trigger a pulse 20 ms wide on the PT6 pin.
E8.10 In Example 8.2, we used the polling method to check for the arrival of edges. Write a
program that uses the interrupt-driven approach to measure the period of an unknown signal.
There will be two interrupts related to the PT0 active edges and zero or more TCNT overfl ow
interrupts to be dealt with.
E8.11 Write a program to generate 10 pulses from the PT6 pin. Each pulse has 60
μ
s high time
and 40
μ
s low time.
 
Search WWH ::




Custom Search