**************************************************************************
* RTI Interupt Example (polling)    EEL-4744     EMS & AAA *
**************************************************************************
********************************************************
* Run a Single Process using the Real-Time Interrupt System but use POLLING
*   (NOT interrupt)
* Port B
* $0F-->$F0-->$0F-->$F0...
* Complement the value in PORTB every 32.77 ms
* USE REAL TIME INTERRUPT AS TIME BASE
* USING an 8.0 MHZ CRYSTAL FOR THE 68HCll CLOCK
********************************************************
* SYMBOL DEFINITIONS
********************************************************
* 68HCll REGISTERS
RTIV		EQU	$FFF0		;RTI Interrupt Vector Location
RAM		EQU	$0000		;Start of RAM
RAMEND		EQU	$01FF		;End of RAM
EEPROM		EQU	$B600		;Start of EEPROM
BASE		EQU	$1000		;Base Address of Internal register
PORTB		EQU	$04		;Output-only PORT B REGISTER
TMSK2		EQU	$24		;TIMER MASK REGISTER
TFLG2		EQU	$25		;TIMER FLAG REGISTER
PACTL		EQU	$26		;PULSE ACCUMULATOR CONTROL REG
OUTPAT1		EQU	$0F		;OUTPUT Pattern for PORTB
********************************************************
* MASKS
********************************************************
BIT6		EQU	%01000000
*
********************************************************
* MAIN PROGRAM
********************************************************
		ORG 	EEPROM
*-----------------------------------------------------
* INITIALIZATION
*-----------------------------------------------------
		LDS	#RAMEND
		LDX	#BASE

* INITIALIZE PORT B
		LDAA	#OUTPAT1	;SET UP PORTB
		STAA	PORTB,X		;ALL OUTPUTS AFFECTED

* INITIALIZE REAL TIME INTERRUPT
		LDAA	#%00000011	;INTERRUPT at 32.7ms with 1's in bits 
		STAA	PACTL,X		;..0 & 1
*					;0's OTHER BITS CAUSE NO PROBLEMS

*   Don't turn on interrupt system, i.e., no CLI; else could write
*   a 0 to bit6 of TMSK2
*		CLRA			;clear bit 6 of TMSK2 to disable
*		STAA	TMSK2,X		;..RTI interrupt; other 0's OK

*   Clear RTIF FLAG
CLEAR		LDAA	#BIT6		;ZEROS IN OTHER BITS
		STAA	TFLG2,X		;..CAUSE NO PROBLEMS

* Main does its work here
WAIT		LDAA	TFLG2,X		; Read the status Register
		ANDA	#BIT6		; Isolate RTIF
		BEQ	WAIT		; Wait until Set
		JSR	TOGGLE
GOON		BRA	CLEAR

********************************************************
* TOGGLE ROUTINE
********************************************************
		ORG	$B700
*------------------------------------------------------
TOGGLE		LDX	#BASE
     		BRCLR	TFLG2,X BIT6 QUIT	;IGNORE IF RTIF not set
*------------------------------------------------------
* SWITCH PORT B OUTPUTS
*------------------------------------------------------
		LDAA	PORTB,X		; Get current pattern
		COMA			; Complement it
		STAA	PORTB,X		; Put it Back
QUIT		RTS
