M68HC11
REFERENCE MANUAL
MAIN TIMER AND REAL-TIME INTERRUPT
MOTOROLA
10-31
When the OCxl control bit is one, a hardware interrupt request is generated whenever
the corresponding OCxF bit is set to one. Before leaving the interrupt service routine,
software must clear the OCxF bit by writing to the TFLG1 register (see
10.2.4 Tips for
Clearing Timer Flags
).
Example 10–4 is a very simple program that uses an output compare to control a soft-
ware time delay. For simplicity, this example uses polled mode and does not cause
any automatic pin changes as the result of the output compare. The program gener-
ates a 10-ms delay like the user might utilize to time an EEPROM program or erase
operation; however, instead of actually programming EEPROM, it will just produce a
pulse on an output port pin so the results can be studied on an oscilloscope. Output-
compare functions can also cause automatic pin changes and generate interrupt re-
quests (see Examples 10–5 and 10–6). A partial listing of the program for Example
10–4 is shown in
Figure 10-9
.
c1bc ce 10 00
c1bf 86 80
c1c1 a7 23
c1c3 6f 04
[3]
[2]
[4]
[6]
INZA
LDX
LDAA
STAA
CLR
#REGBAS
#$80
TFLG1,X
PORTB,X
Point to register block
Clear any pending OC1F flag
Initialize port B to zeros
c1c5 86 01
c1c7 a7 04
[2]
[4]
TOP4A
LDAA
STAA
#1
PORTB,X
Top of Ex10-4a
Set LSB of port B
* This is where the 10mS delay part actually starts
*
LDD
TCNT,X
ADDD
#20000
STD
TOC1,X
c1d0 1f 23 80 fc[7] LP1
BRCLR
TFLG1,X $80 LP1 Loop here till OC1F=1
c1c9 ec 0e
c1cb c3 4e 20
c1ce ed 16
[5]
[4]
[5]
Get current timer count
What will count be in 10mS
Set OC1 to trigger then
*Delay is actually done here; rest is just support
c1d4 1d 23 7f
c1d7 6f 04
c1d9 18 ce 16 4e[4]
c1dd 18 09
c1df 26 fc
c1e1 20 e2
[7]
[6]
BCLR
CLR
LDY
DEY
BNE
BRA
TFLG1,X $7F Clear OC1F
PORTB,X
#5710
Clear PB0 pin
5710*(7~/loop) = about 20ms
Top of software delay loop
Loop ’till Y is zero
Repeat continuously for O-scope
[4]
[3]
[3]
DLP1
DLP1
TOP4A
Figure 10-9 Simple Output-Compare Example
This example is only intended to show the most basic use of an output-compare func-
tion. It is not intended to be an especially efficient way to delay a fixed period of time.
The following three instructions are a simpler way to delay if no other tasks are to be
performed during the delay:
c1d9 18 ce 16 4e[4]
c1dd 18 09
c1df 26 fc
By contrast, an output compare in interrupt-driven mode has the advantage of allowing
LDY
DEY
BNE
#5710
5710*(7~/loop)= about 2Oms
Top of software delay loop
Loop ’till Y is zero
[4]
[3]
DLP1
DLP1