Hardware Reference
In-Depth Information
movb #$04,TCTL1 ; change pin action to toggle
clr HIorLO ; LoCnt will be the delay count next time
bra $ ; prepare to perform other operations
; *********************************************************************************
; OC5 interrupt service routine starts a new OC5 operation with delay count equal to
; HiCnt or LoCnt depending on whether HIorLO flag is 1 or 0. After starting a new OC5
; operation, toggle HIorLO flag.
; *********************************************************************************
OC5ISR
tst
HIorLO
; which delay count should be added?
beq
addLow
; if 0 then select LoCnt
ldd
TC5
; select HiCnt as the delay count for
addd
#HiCnt
; the new OC5 operation
std
TC5
;
clr
HIorLO
; toggle HIorLo flag
rti
addLow
ldd
TC5
; select LoCnt as the delay count for
addd
#LoCnt
; the new OC5 operation
std
TC5
;
movb
#1,HIorLO
; toggle HIorLO flag
rti
end
The C language version of the program is as follows:
#include “c:\cwHCS12\include\hcs12.h”
#define HiCnt 1200
#define LoCnt 1800
char HiorLo;
void main (void)
{
TSCR1
5 0x90;
// enable TCNT and fast timer flag clear
TSCR2
5 0x03;
// disable TCNT interrupt, set prescaler to 8
TIOS
| 5 OC5;
// enable OC5 function
TCTL1
5 0x0C;
// set OC5 action to pull high
TFLG1
5 0xFF;
// clear all CxF flags
TC5
5 TCNT 1 10;
while(TFLG1 & C5F);
// wait until C5F is set
TCTL1
5 0x04;
// set OC5 pin action to toggle
TC5
15 HiCnt;
// start an new OC5 operation
HiorLo
5 0;
// add LoCnt for the next OC5 operation
TIE
5 0x20;
// enable OC5 interrupt locally
asm(“cli”);
// enable interrupt globally
while(1);
}
interrupt void oc5ISR (void)
{
if(HiorLo){
TC5
15 HiCnt;
HiorLo
5 0;
}
Search WWH ::




Custom Search