Hardware Reference
In-Depth Information
else{
TC5 15 LoCnt;
HiorLo 5 1;
}
}
The OC5 interrupt vector is set up using the following function (in vectors.c):
extern void near oc5ISR(void);
#pragma CODE_SEG __NEAR_SEG NON_BANKED
#pragma CODE_SEG DEFAULT // Change code section to DEFAULT.
typedef void (*near tIsrFunc)(void);
const tIsrFunc _vect[] @0xFFE4 5 {
oc5ISR
};
Using the OC5 interrupt to restart the subsequent OC5 operations allows the HCS12 to
continue to perform other operations.
Example 8.5
Write a function to generate a time delay that is a multiple of 1 ms. Assume that the
E-clock frequency is 24 MHz. The number of milliseconds is passed in Y. Also write an in-
struction sequence to test this function.
Solution: There are many ways to create a 1-ms time delay using the output-compare function.
One method is
Set the prescaler to TCNT to 8.
Perform the number of output-compare operations given in Y with each operation
creating a 1-ms time delay. The number to be added to the TC0 register is 3000
(3000 3 8 4 24,000,000 5 1 ms).
The corresponding assembly function is as follows:
delayby1ms
pshd
movb
#$90,TSCR1
; enable TCNT and fast flag clear
movb
#$03,TSCR2
; configure prescaler to 8
bset
TIOS,OC0
; enable OC0
ldd
TCNT
again0
addd
#3000
; start an output-compare operation
std
TC0
; with 1-ms time delay
wait_lp0
brclr
TFLG1,OC0,wait_lp0
ldd
TC0
dbne
y,again0
puld
rts
The C language version of the function and its test program are as follows:
#include “c:\cwHSC12\include\hcs12.h”
void delayby1ms(int k);
void main (void)
 
Search WWH ::




Custom Search