**********
* Program COUNT (6811)
*
* Continually counts the number of 0 to 1 transitions on PA0 (IC3) input.
* Displays in decimal form on discrete LEDs (PORTB).
*
* Uses IC3 interrupt.
*
* Peter H. Anderson, MSU,  Checked 29 Oct 90; 15 Jan 93
**********

PSCT		EQU $C000
DSCT		EQU $D000
IDSCT		EQU $D300

STACKTP		EQU $0045

IC3_VECTOR	EQU $00E2	* for counting events, 0 to 1 transitions

REG_BASE	EQU $1000

TMSK1		EQU $22 	* Int mask, Bit 0 corresponds to IC3
TFLG1		EQU $23 	* Bit 0 is logic 1 when interrupted
TCTL2		EQU $21         * Config of input to interrupt

PORTB		EQU $04

	ORG PSCT

	SEI			* no interrupts
	LDS #STACKTP

	LDY #REG_BASE
	CLR PORTB,Y

	CLR COUNT

	BCLR TCTL2,Y %00000010  * IC3 int on positive edge
	BSET TCTL2,Y %00000001	* B1 and B0 set to 01
	BSET TMSK1,Y $01	* Set Mask for IC3 ints
AGN
	CLI			* enable ints
	WAI			* wait until interrupted
	SEI
	BRA AGN

IC3_INTSERV

	BCLR TFLG1,Y %11111110	* interrupt serviced
* or 	BSET TFLG1,Y %00000001
	LDAA COUNT		* add one to count (decimal)
	ADDA #$01
	DAA
	STAA COUNT
	STAA PORTB,Y		* and display on discrete LEDs
	RTI

	ORG IC3_VECTOR

	JMP IC3_INTSERV

	ORG DSCT

COUNT	RMB 1


