This is my first AVR Assembler program which will do something other than turning on a LED.

Code: Select all
/*
* test.asm
*
* Created: 8/22/2011 1:19:51 AM
* Author: Harindra
*/
.NOLIST
.INCLUDE "m16def.inc"
.LIST
.DEVICE ATMEGA16
.def i=r16
.def temp=r17
.def buffer=r18
.CSEG
.ORG $000
rjmp main;$0
reti;$002
reti;$004
reti;$006
reti;$008
reti;$00A
reti;$00C
reti;$00E
reti;$010
reti;$012
reti;$014
rjmp USART_RXC;$016
;
;or this way?
;.ORG $016
;rjmp USART_RXC
;-------------------------------
main:
;init stack
ldi temp,HIGH(RAMEND)
out sph,temp
ldi temp,LOW(RAMEND)
out spl,temp
call INIT_USART
loop:rjmp loop;loop forever
;--------------------------------
USART_RXC:
cli
push i
in i,SREG
push i
in buffer,UDR
ready:
ldi i,(UCSRA)&(1<<UDRE)
tst i
breq ready
out UDR,buffer
pop i
out SREG,i
pop i
reti
INIT_USART:
;init usart for 4800bps baud
;F_CPU is 12MHz
;8bit data, noparity
ldi i,$0
out UBRRH,i
ldi i,$9B
out UBRRL,i
ldi i,(1<<RXCIE)|(1<<RXEN)|(1<<TXEN)
out UCSRB,i
ldi i,(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0)
out UCSRC,i
sei
ret
It seems like i have a problem in setting up the UCSRC register. I am still working on it