**********
* Program TIME_2 (6811)
*
* Illustrates use of a 16 bit location to perform loop timing.
* Blinks least sig LED on and off.
* 
* Note that each instruction cycle is 0.5 usecs.
*
* Calculation of timing:
*
*	60,000 * (3 + 2 + 2 + 3) = 600,000 cycles 
*
*	600,000 cycles * 0.5 usecs / cycle = 0.3 secs
*
* This ignores the overhead in the main and the subroutine.
*
* P. H. Anderson, MSU, 14 Jan, '93
**********

PSCT	EQU  $C000
DSCT	EQU  $D000
IDSCT	EQU  $D300

REG_BASE	EQU  $1000
STACKTP 	EQU  $0045

PORTB	EQU  $04
PORTC	EQU  $03
DDRC	EQU  $07

	ORG PSCT

	OPT c		* listing to have cycles

	LDS #STACKTP	* initialize stack pointer

	LDY #REG_BASE
	CLR DDRC,Y	* port c configured as 8-bit input

	LDAA #$01	* pattern initialized
TOP
	BSR DELAY
	EORA #01	* invert the output pattern
	STAA PORTB,Y	* output to LEDs
	BRA TOP

DELAY
* provides delay using the index register

	PSHX
	LDX #60000	* 60,000 decimal
L1
	DEX
	NOP
	NOP
	BNE L1
	PULX
	RTS


