;***************************************************************************
;* File Name		:ee_table.asm
;* Title		:Reading a table stored in EEPROM and display
;* Date	 		:09/06/97
;* Version 		:1.0
;* Target MCU		:AT90S1200
;* 
;* DESCRIPTION
;* Strings stored as a table in EEPROM are sent via RS232 to a display.
;***************************************************************************

;***** Directives
.nolist
.include "1200def.inc"
.list

.ESEG	
text1:	;Welcome to
	.db	87,101,108, 99,111,109,101, 32,116,111, 32
	;Atmel's new AVR 		
	.db	65,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	
.CSEG

; Registers used for EEPROM access (must be < r16)
;---------------------------------------------------------------------------
.def	EEwtmp		= r0	;temporary storage of address
.def	EErtmp		= r0	;temporary storage of address
.def	EEdrd		= r0	;result data byte
.def	EEdrd_s		= r1	;result data byte

; Registers used for EEPROM access (must be >= r16)
;---------------------------------------------------------------------------
.def	EEdwr		= r16	;data byte to write to EEPROM
.def	EEawr		= r17	;address to write to
.def	EEard		= r16	;address to read from
.def	EEdwr_s		= r16	;data to write

; Registers used for SW uart (must be >= r16)
;---------------------------------------------------------------------------
.def	d_bcntr 	= r23 	;bit counter
.def	d_srdel 	= r24 	;delay loop variable
.def	d_txrx 		= r25 	;async serial data byte transmit/received

; Main Program Register variables
;---------------------------------------------------------------------------
.def	dly	= r17
.def	delcnt	= r18		; Loop Counter
.def	temp	= r19

;***** Interrupt vector table

	rjmp	RESET		; Reset handle
	reti			; External Interrupt0 handle
	reti			; Overflow0 Interrupt handle
	reti			; Analog Comparator Interrupt handle

;***** Includes

.include "eeprom.inc"
.include "uart.inc"

;***** Subroutines

DELAY:	clr	delcnt		; Init Loop Counter
loop1:	dec	delcnt
	nop
	brne	loop1
	dec	dly
	brne	loop1
	ret

;***** Main


RESET:	rcall 	d_sersetup	; Setup UART pins
	ser	temp
	out	DDRB, temp
	out	PORTB,temp	; Setup PortB
	
start:	ldi	temp, text1-1	
	out	EEAR,temp	; Set address of string
	
loop:	rcall	EERead_seq	; get EEPROM data
	out	PORTB, EEdrd_s	; write to PortB
	mov	d_txrx,EEdrd_s	;   and to transmit register
	rcall	d_writeser	; Send character
	
	ldi	dly, $FF	; Initialize delay of about 65 ms
	rcall	DELAY		; Number of cycles = 1026 * del + 4

	tst	EEdrd_s		; last character? (0-terminated string)
	breq	start
	
	
	
	rjmp	loop		; Repeat endless


