;***************************************************************************
;* File Name		:cc_table.asm
;* Title		:Reading a table stored in code area and display
;* Date	 		:09/28/97
;* Version 		:1.0
;* Target MCU		:AT90S8515
;* 
;* DESCRIPTION
;* Strings stored as a table in program memory 
;* are sent via RS232 to a display.
;***************************************************************************

;***** Directives
.device	 at90s8515
.nolist
.include "8515def.inc"
.list


; Main Program Register variables
;---------------------------------------------------------------------------
.def	temp	= r16
.def	dly	= r17
.def	delcnt	= r18		; Loop Counter


;***** Interrupt vector table

	rjmp	RESET		; Reset handle
	reti			; External Interrupt0 handle
	reti			; External Interrupt1 handle
	reti			; T/C1 Capture Event Interrupt handle
	reti			; T/C1 CompareA Interrupt handle
	reti			; T/C1 CompareB Interrupt handle
	reti			; T/C1 Overflow Interrupt handle
	reti			; T/C0 Overflow Interrupt handle
	reti			; SPI Transfer Complete Interrupt handle
	reti			; UART Rx Complete Interrupt handle
	reti			; UART Data Register Empty Interrupt handle
	reti			; UART Tx Complete Interrupt handle
	reti			; Analog Comparator Interrupt handle


;***** Table in Code Area (behind interrupt vector table)

text1:	;Welcome to A
	.db	 87,101,108, 99,111,109,101, 32,116,111, 32, 65
	;tmel's new AVR 		
	.db	116,109,101,108, 39,115, 32,110,101,119, 32, 65, 86, 82
	;micros.	  	 
	.db	32, 109,105, 99,114,111,115, 46, 13, 10, 00	


;***** Includes

.include "hw_uart.inc"


;***** Subroutines

DELAY:	clr	delcnt		; Init Loop Counter
loop1:	dec	delcnt
	nop
	brne	loop1
	dec	dly
	brne	loop1
	ret


;***** Main


RESET:	ldi	temp, LOW(RAMEND)
	out	SPL, temp		; Initialize SPL
	ldi	temp, HIGH(RAMEND)
	out	SPH, temp		; Initialize SPH

	rcall 	uart_init	; Initialize UART
	ser	temp
	out	DDRB, temp
	out	PORTB,temp	; Setup PortB
	
start:	ldi	ZL, LOW(text1<<1)	
	ldi	ZH, HIGH(text1<<1)	; Load Z with address of string
	
loop:	lpm			; get data from program memory
	inc	ZL
	out	PORTB, R0	; write to PortB
	mov	temp, R0		;   and to transmit register
	rcall	putc		; Send character

	ldi	dly, $40	; Initialize delay of about 16 ms
	rcall	DELAY		; Number of cycles = 1026 * del + 4

	
	tst	R0		; last character? (0-terminated string)
	breq	start
	
	rjmp loop		; Repeat endless


