;**************************************************************************
;Name:		Output Compare
;Author:		Gregory Reeves Jr.
;Date:		July 30, 2005
;Function:	Generates a 75% duty cycle,3100Hz square wave.
;Process:		None
;Function:	None
;**************************************************************************

		ORG $2000

		JMP MAIN

TCTL1	EQU $1020	;equating memory locations
TMSK1	EQU $1022
TFLG1	EQU $1023
TCNT		EQU $100E
TOC2		EQU $1018
TOC2IV	EQU $00DC
On_cnts	RMB 2
Off_cnts 	RMB 2
PORTA  	EQU $1000




MAIN		SEI

		LDAA #$7E		;setting the interrupt vector table
		STAA TOC2IV

		LDD #TOCIV
		STD TOC2IV+1

		LDD #1800		;count value needed for ontime
		STD On_cnts

		LDD #38200		;count value needed for offtime
		STD Off_cnts

		LDD TCNT		;sets the first time of TOC2
		ADDD On_cnts
		STD TOC2

		LDAA #$40		;intializing the registers
		STAA TFLG1
		STAA TMSK1
		STAA TCTL1	;toggles the output

		CLI			;turning on the interrupts

LOOP:	BRA LOOP

;**************************************************************************
;Name:		TOCIV
;Author:		Gregory Reeves Jr.
;Date:		July 30, 2005
;Function:	Interrupt sets up to output caputure on the next edge.
;Process:		None
;Function:	None
;On Call		On and off time
;**************************************************************************
TOCIV 	LDAA #$40		;resets the OC2F bit
		STAA TFLG1

		LDAA PORTA	;check oc2 pin for on or off state
		ANDA #$40
		BNE ON

		LDD TOC2		;sets up for the off time sequence
		ADDD Off_cnts
		STD TOC2
		BRA EXIT

ON		LDD TOC2		;sets up for the next ontime sequence
		ADDD On_cnts
		STD TOC2

EXIT 	RTI			;return from the interrupt


