© 2001 Ubicom, Inc. All rights reserved. - 7 - www.ubicom.com Asynchronous Transmitter & Receiver (UART) Virtual Peripheral Implementation AN38 ;---------------------------VP: RS232 Receive-------------------------------------
;*********************************************************************************
; Virtual Peripheral: Universal Asynchronous Receiver Transmitter (UART)
; These routines send and receive RS232 serial data, and are currently configured
; (though modifications can be made) for the popular "No parity-checking, 8 data bit,
; 1 stop bit" (N,8,1) data ;format. RECEIVING: The rx_flag is set high whenever a valid
; byte of data has been received and it ;is the calling routine’s responsibility to reset
; this flag  once the incoming data has been collected.       
; Output variable(s) : rx_flag, rx_byte
; Variable(s) affected : tx_divide, rx_divide, rx_count
; Flag(s) affected : rx_flag
; Program cycles: 23 worst case
; Variable Length?  Yes.
;*******************************************************************************
rs232Receive _bank rs232RxBank ;2 sb rs232RxPin ;1 get current rx bit clc ;1   snb rs232RxPin ;1   stc ;1   test     rs232RxCount ;1 currently receiving byte? sz ;1   jmp :rxbit ;1 if so, jump ahead mov w,#9      ;1 in case start, ready 9 bits sc ;1 skip ahead if not start bit mov      rs232RxCount,w ;1 it is, so renew bit count mov      w,#UARTRxStDelay ;1 ready 1.5 bit periods (50MHz) mov      rs232RxDivide,w ;1   :rxbit decsz rs232RxDivide ;1 middle of next bit?           jmp :rs232RxOut ;1 mov w,#UARTRxDivide ;1 yes, ready 1 bit period (50MHz)     mov rs232RxDivide,w ;1   dec rs232RxCount ;1 last bit? sz ;1  if  not? rr       rs232RxByte        ;1 then save bit snz                              ;1 if so, setb    rs232RxFlag                 ;1,23 then set flag :rs232RxOut jmp isrOut ;7 cycles until mainline program resumes     ;execution isrThread2 ; Serviced at ISR rate/16 jmp isrOut            ; 7 cycles until mainline program resumes    ; execution isrThread3 ; Serviced at ISR rate/16 jmp isrOut ; 7 cycles until mainline program resumes    ; execution isrThread4      ; Serviced at ISR rate/16 jmp isrOut ; 7 cycles until mainline program resumes    ; execution isrThread5 ; Serviced at ISR rate/16 jmp isrOut ; 7 cycles until mainline program resumes    ; execution