© 2001 Ubicom, Inc. All rights reserved.
- 6 -
www.ubicom.com
AN38
Asynchronous Transmitter & Receiver (UART) Virtual Peripheral Implementation
;*******************************************************************************
; VP: VP Multitasker
; ISR TASKS
;*******************************************************************************
IsrThread1
; Serviced at ISR rate/4
;---------------------------VP: RS232 Transmit----------------------------------
;*******************************************************************************;
; 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 rs232Rxflag is set high whenever a valid byte of data has been received
; and it is the calling routines responsibility to reset this flag once the incoming
; data has been collected.
; TRANSMITTING : The transmit routine requires the data to be inverted and loaded
; (rs232Txhigh+rs232Txlow) register pair (with the inverted 8 data bits stored in rs232Txhigh
; and rs232Txlow bit 7 set high to act as a start bit). Then the number of bits ready for
; transmission (10=1 ;start + 8 data + 1 stop) must be loaded into the rs232Txcount register.
; As soon as this latter is ;done, the transmit routine immediately begins sending the data.
; This routine has a varying ;execution rate and therefore should always be placed after any
; timing-critical virtual peripherals ;such as timers, adcs, pwms, etc. Note:
;
; The transmit and receive routines are independent and either may be removed, if not needed,
; to ;reduce execution time and memory usage, as long as the initial "BANK serial" (common)
; instruction is kept.
; Input variable(s) : rs232Txlow (only high bit used), rs232Txhigh, rs232Txcount .
; output variable(s) : rs232Rxflag, rs232Rxbyte
; variable(s) affected : rs232Txdivide, rs232Rxdivide, rs232Rxcount
; Flag(s) affected : rs232Rxflag
; Program cycles: 17 worst case
; Variable Length? Yes.
;*******************************************************************************
rs232Transmit
_bank
rs232TxBank
;2 switch to serial register bank
decsz
rs232TxDivide
;1 only execute the transmit routine
jmp
:rs232TxOut
;1
mov
w,#UARTTxDivide
;1 load UART baud rate (50MHz)
mov
rs232TxDivide,w
;1
test
rs232TxCount
;1 are we sending?
snz
;1
jmp
:rs232TxOut
;1
:txbitclc
;1 yes, ready stop bit
rr
rs232TxHigh
;1 and shift to next bit
rr
rs232TxLow
;1
dec
rs232TxCount
;1 decrement bit counter
snb
rs232TxLow.6
;1 output next bit
clrb
rs232TxPin
;1
sb
rs232TxLow.6
;1
setb
rs232TxPin
;1,17
:rs232TxOut