Full Version : Jack Tidwell's RS232 Cirular Buffer Routine (ASM)
avr >>ASSMBLER ROUTINES >>Jack Tidwell's RS232 Cirular Buffer Routine (ASM)


Admin5- 04-19-2006
Queue.zip RS232 circular buffer AT90s2313 J Tidwell


CODE

; 5/99 by Jack Tidwell

;*******************************************

;*Simple & effective rs232 circular buffer *

;*  Interupt driven, thus 'transparent' to *

;*  User functions                         *

;*******************************************



.include "2313def.inc"



.equ BUFSIZE = 10



.def rxhead =r16

.def rxtail =r17

.def tempchar=r18



.DSEG

Buf: .byte BUFSIZE



.CSEG



;************************

;* The actual RS232 ISR *

;************************

Rs232ISR:

push r1

in r1,SREG ; preserve main OS status reg.

push r2

push zl

push zh

clr r2

ldi zl,low(Buf); ptr to our rxbuffer

ldi zh,high(Buf)

add zl,rxtail

adc zh,r2

in r2,UDR ; get the incomming char

st z,r2 ; Buf[rxtail++] = UDR

inc rxtail

cpi rxtail,BUFSIZE

brlo Rs232inx

clr rxtail ; Circle around to the first buffer pos.

Rs232inx:

;***** Xoff calcs go here *****

pop zh

pop zl

pop r2

out SREG,r1 ; restore previous status reg

pop r1

reti  ; return to normal pgm status.

;

;**************************

;* The RS232 FIFO manager *

;**************************

Rs232GetByte:

clr tempchar

cp rxhead,rxtail

breq Rs232GetBytexit

clr r2

ldi zl,low(Buf); Pointer to the rxbuffer (FIFO)

ldi zh,high(Buf)

add zl,rxhead

adc zh,tempchar

ld tempchar,z; tempchar = Buf[rxhead++]

inc rxhead

cpi rxhead,BUFSIZE

brlo Rs232Gbx

clr rxhead ; Circle around to the first buffer pos.

Rs232Gbx:

;***** Xon calcs go here *****

sec  ; This is not need for ASCII data

ret  ; as a zero value returned in tempchar works

Rs232GetBytexit: ; But, for binary data, zero may be valid!

clc  ; Return 'No' bytes in yet.

ret

;

;******************************

;* And The RS232 GetChar Loop *

;* wait until a char comes in *

;******************************

GetChar:

rcall Rs232GetByte

brcc GetChar

ret

;





Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.