
AN155
12 Rev. 1.1
and set the doneFlag. The doneFlag is used as a
handshaking mechanism for the main loop to display
the done message.
If the motor state is not Done, the timer ISR will
calculate the value for the next interrupt and write to the
TL0 and TH0 special function registers. Next the
TableIndex or SlewCount is modified according to
the motor State. During Acceleration, the TableIndex
is incremented. During Deceleration the TableIndex is
decremented. If the motor state is Slewing the
SlewCount will be decremented.
5.5. UART Functions
The UART functions implement fully buffered I/O using
the C8051 receiver and transmitter. The benefit of using
buffered I/O is that most short messages will be sent or
received in a non-blocking manner. This means that the
CPU does not have to wait for each byte to be
transmitter or received. The user code does not write or
read data directly to the serial port. Instead the user
functions write or read data to the buffers. A UART
interrupt service routine transmits characters from the
write buffer and places received characters into the read
buffer.
The UART functions are modeled after the ANSI stdio
library functions. Each function has been optimized for
use in a small microcontroller. This is more code
efficient than including the entire stdio library and
rewriting the bottom layer functions.
The put string puts() function is used to display
messages on the terminal. There are two versions of
the get integer & put integer functions, one for 8-bit
unsigned char data and one for 16-bit unsigned int data.
The middle layers of the serial protocol are the put
character putc() and get character getc() functions.
These are the lowest level functions that should be
called by the user code.
The bottom layers of the serial communications protocol
are the write character writec() and read character
readc() functions. These functions write and read
directly to the read and write buffers. These functions
are called from the getc() and putc() functions. The
user code should not use readc() and writec()
functions directly. The readc() and writec()
functions momentarily disable UART interrupts while
accessing the read and write buffers to avoid
contentions. The writec() function also restarts the
transmitter if it is idle.
A single UART Interrupt service routine UART_ISR is
used for both transmit and receive interrupts. The ISR
must check both the transmitter and receiver to
determine which needs servicing. If the write buffer is
empty, the UART_ISR will set the TX_Idle flag bit and
clear the transmit interrupt flag without writing to SBUF0.
This will disable the transmitter until restarted. The
TX_Idle flag bit is used for handshaking with the
writec() function. The writec() function checks the
status of the TX_Idle flag bit and restarts the
transmitter if necessary.
6. References
1. Takashi Kenjo, “Stepping motors and their
Microprocessor Controls”, Oxford University Press,
1984.
2. Ken Berringer, “Linear Velocity Control of Stepper
Motors”,
Incremental Motion Systems Symposium, June 1999
Comentarios a estos manuales