;************************************************
;* TIMER 0-CONTROLLED LAMP TEST
;*
;* Chip Number 		: U1
;* File Name 		: Program 003 Timed Test.asm
;* Date				: 01.25.2003
;* Last Update		: 05.19.2004
;* Version			: 1.0.1
;* Support Telephone: unlisted
;* Support Fax		: unlisted
;* Support E-mail	: brm016000@utdallas.edu
;* Target MCU		: AT90S2313
;*
;* DESCRIPTION
;*
;* Lamp test function (similar to Program 002)
;* timed by Internal Timer 0 ("TCNT0"). Unlike 
;* the previous lamp test version, the rotating
;* LED patter will be timed based on oscillations
;* from the 4.00MHz XTAL.
;*
;* * Revised for optimization 05.19.2004
;*************************************************	
;.device AT90S2313

.nolist						; Don't show list directives
.include "2313def.inc"
.list

.cseg						; Code Segment (Flash storage)
.org 0x00					; Begin at address 0x00

	rjmp maain				; Reset vector
;########################
;# Interrupt Vectors	#
;########################
	RETI				;Int0 Interrupt
	RETI				;Int1 Interrupt
	RETI				;TC1-Capture
	RETI				;TC1-Compare Match
	RETI				;TC1-Overflow
	RETI				;TC0-Overflow
	RETI				;UART Receive Transfer Complete
	RETI				;UART Data Register Empty
	RETI				;UART Transmit complete
	RETI				;Analog Comparator
;########################
;# End Interrupt Vectors#
;########################
main:
	ser R16				; R16 <--$FF.
	out DDRB,R16		; PORTB Data Direction Setup.

	ldi R16,(RAMEND)	; Load RAMs highest address (the end).
	out SPL,R16			; Stack pointer setup.
	
	ldi R16,0b00000100	; Setup Timer Prescale for 512us periods.
	out TCCR0,R16		; Send configuration

	ldi R17,0b11000000	; Pattern to display.

	clc					; Pre-clear the carry flag

loop:
	in R16,TCNT0		; In from Timer Count.
	tst R16				; Test for zero.  Has timer overflowed?
	brne loop			; If not zero, return to the loop.
	ldi R16,1
	out TCNT0,R16
	ror R17				; Rotate through carry flag (SREG)
	out PORTB,R17		; Display updated bit pattern.
	rjmp loop			; Return to loop