Hardware Reference
In-Depth Information
The assembly program that implements this algorithm for an HCS12DP256 running with
a 24-MHz E-clock is as follows:
#include “c:\miniide\hcs12.inc”
hi_freq equ
1250
; delay count for 1200 Hz (with 1:8 prescaler)
lo_freq equ
5000
; delay count for 300 Hz (with 1:8 prescaler)
toggle
equ
$04
; value to toggle the TC5 pin
org
$1000
delay
ds.w
1
; store the delay for output-compare operation
org
$1500
lds
#$1500
movw
#oc5_isr,UserTimerCh5 ; initialize the interrupt vector entry
movb
#$90,TSCR1
; enable TCNT, fast timer flag clear
movb
#$03,TSCR2
; set main timer prescaler to 8
bset
TIOS,OC5
; enable OC5
movb
#toggle,TCTL1
; select toggle for OC5 pin action
ldd
#hi_freq
std
delay
; use high-frequency delay count first
ldd
TCNT
; start the high-frequency sound
addd
delay
; “
std
TC5
; “
bset
TIE,OC5
; enable OC5 interrupt
cli
; “
forever
ldy
#5
; wait for half a second
jsr
delayby100ms
; “
movw
#lo_freq,delay
; switch to low-frequency delay count
ldy
#5
jsr
delayby100ms
movw
#hi_freq,delay
; switch to high-frequency delay count
bra
forever
oc5_isr ldd
TC5
addd
delay
std
TC5
rti
#include c:\miniide\delay.asm”
end
In this program, both the OC0 and OC5 channels rely on the TCNT for timing control. One
should use the same prescaler throughout all the timing operations. The C language version of
the program to generate the siren to be compiled by CodeWarrior is as follows:
#include “c:\cwHCS12\include\hcs12.h”
#include “c:\cwHCS12\include\delay.h”
#define HiFreq 1250
#define LoFreq 5000
int
dlycnt;
// delay count for OC5 operation
void
oc5ISR(void);
void
main(void)
{
TSCR1 5 0x90;
// enable TCNT and fast timer flag clear
TSCR2 5 0x03;
// set prescaler to TCNT to 1:8
Search WWH ::




Custom Search