© 2001 Ubicom, Inc. All rights reserved.
- 4 -
www.ubicom.com
AN38
Asynchronous Transmitter & Receiver (UART) Virtual Peripheral Implementation
3.3
Initialization Section
This section provides initialization for the UART Virtual
Peripheral. This has to be included with the initialization
of all other ports and registers, prior to entering the main
loop of the application.
_bank
rs232TxBank
;select rs232 bank
mov
w,#UARTTxDivide ;load Txdivide
;with UART baud
;rate
mov
rs232TxDivide,w
Initialization is required to send the data at the desired
baud rate. The value of
UARTTxDivide specifies the num-
ber of times the thread has to be serviced before a bit is
transmitted. For example, at 9600 baud the value of
UARTTxDivide is 6 (57600/9600=6), which means that a
bit is transmitted once for every six times isrThread1 is
called.
3.4
Interrupt Section
This section is the UART Virtual Peripheral ISR. The flow
of the interrupt service routine is demonstrated by the
flowchart in Figure2-1.
The ISR returns with a "retiw" value of -217 every 4.32
microseconds at an oscillator frequency of 50 MHz.
The events that occur on an interrupt are:
1.An interrupt occurs whenever the RTCC value rolls
from $FF to $00. The interrupt jumps to the ISR at $00.
2.In the ISR, the value of isrMultiplex is incremented.
Initially it is zero.
isrMultiplex implements rotation
among the slots for threads called by the multitasker.
isrMultiplex is added to the value of the program
counter to jump into a table of jump instructions for the
threads.
3.In isrThread1 , the UART Virtual Peripheral ISR is ex-
ecuted.
4.The value of rs232TxDivide is checked for zero, to
confirm whether a bit has to be transmitted in this cycle.
The value of
UARTTxDivide is loaded to
rs232TxDivide .
5.The value of rs232TxCount is checked to confirm the
presence of data to be transmitted. If the value is not
zero, there is data to be transmitted, in which case the
transmit routine is executed.
6.The data stored in rs232TxHigh is pushed to the W
register.
7.The MSB of the rs232TxLow register is set, which is the
start bit. A total of ten bits are transmitted, which con-
sists of 1 start bit + 8 data bits + 1 stop bit. The receiver
has to be configured for this format.
8.The bits are rotated to the right and fed to the
rs232TxLow register.
9.Bit 6 of the rs232TxLow register is transmitted on the
TX pin.
A similar procedure is used to receive the incoming
bytes.