; ************************************
; * UART Communication  by PEK '2000 
; *
; * The program have one interrupt
; * routine which receive
; * information on RxD.
; * When data comes on RxD line the
; * program send data+1 back on TxD.
; *
; * Use a 4 MHz crystal!
; ************************************


.include "8515def.inc"


; ************************************
; * Variable Definitions             
; ************************************
.def	temp	=R16
.def	data	=R17


; ************************************
; * Start of Code                    
; ************************************
.cseg
.org 0
	rjmp	start
.org 9	
	rjmp	rx_comp			; UART Rx Complete Handler


start:	ldi	temp,low(RAMEND)
	out	SPL,temp		; Set stack pointer to last internal RAM location
	ldi	temp,high(RAMEND)
	out	SPH,temp
		
	ldi	temp,0x98
	out	UCR,temp		; Rx INT, Rx Enable, Tx Enable
	ldi	temp,12
	out	UBRR,temp		; 19200 Baud (4 MHz crystal)

	sei				; Enable global interrupts
	
loop:
	rjmp	loop


; ** UART Rx Complete Handler ********
rx_comp:
	in	data,UDR		; Get data from UART Data Register
	inc	data			; data = data+1
	out	UDR,data		; Send new data
	reti
