;aruna and mazhalai ;4 dec 99 ;uart prog for 8515 ver1...and it worked!!! ;prog recieves a data and outputs it to port B and echoes it ;back by incrementing the same ;transmission and reception is done at 9600 bps .include"..\..\8515def.inc" .def rtemp=r17 ;temporary register .def rreg=r18 ;register for recieving data .def treg=r19 ;register for transmitting .equ baudrate=$33 ;baud rate of 9600 bps for a clock frequency of 8 Mhz .equ RXC=7 ;UART recieve complete flag( 7th bit of USR register) .equ UDRE=5 ;UART data register empty flag(5th bit of USR register) .cseg .org 0 rjmp RESET ;reset handle rjmp RESET rjmp RESET RESET: ldi r16, low(RAMEND) ;initialising stack out SPL,r16 ldi r16,HIGH(RAMEND) out SPH,r16 ldi r16,255 ;initialising port B for output out DDRB,r16 rcall init_uart ;initialising 8515 for transmit and recieve up: rcall rxcomp ;recieving data out portb,rreg ;outputting data at port B inc rreg ;incrementing recieved data mov treg, rreg rcall txcomp ;transmitting data rjmp up ;subroutine for initialising baudrate and UART control register init_uart: ldi rtemp, baudrate ;setting baud rate out UBRR,rtemp ldi rtemp, $18 ;initialising UART control register out UCR, rtemp ret ;subroutine for recieving data rxcomp: sbis USR,RXC ;poll to check if char received rjmp rxcomp in rreg,UDR ;put received data in rreg ret ;subroutine for transmitting data txcomp: sbis USR,UDRE ;poll to check end of transmission rjmp txcomp out UDR, treg ret