;**************************************************
;Type:		M68HC12 Assembly Program
;Name:		example10_4.asm
;Date:		March 2005
;Purpose:	Use Timer Output Compare 0 to generate 
;		a 1-ms time delay on PTT0 OF PORTT
;Note:	modificaiton of Example 10-4 on page 306
;	of the textbook by Cady and Sibigtroth
;**************************************************

; Constant Equates
LOOPS:	EQU	50000	; number of cycles
; I/O Register Equates

; Make DELAY_1MS visible externally
	xdef	WAIT

CodeSec: SECTION

WAIT:
;Enable the timer. A/D will not work if timer is off
	BSET	TSCR1,mTSCR1_TEN  ; at 0x46
; Set pin action
	BSET TCTL2,mTCTL2_OM0
	BCLR TCTL2,mTCTL2_OL0
; Enable Output Compare Channel
	BSET TIOS,mTIOS_IOS0
	BSET TFLG1,mTFLG1_C0F ; Clear the flag
; Just generate a 1 ms delay here
; Grab the value of the TCNT register
 	LDD TCNT  ; at 0x44
	ADDD #LOOPS
	STD TC0 ; at 0x50
; Wait until the flag is set
SPIN:	BRCLR TFLG1,mTFLG1_C0F,SPIN ;at 0x4E
	RTS
