Page 291 - Programming Microcontrollers in C
P. 291
276 Chapter 5 Programming Large 8-Bit Systems
found on parts from all families of Motorola microcontrollers. The
SCI performs the operation of a full function universal asynchronous
receiver transmitter (UART). It can operate with most standard baud
rates, and several nonstandard rates. Control of this peripheral is
through the BAUD register, the SCSR (serial communications status
register), and both SCCR1 and SCCR2 (serial communications control
registers 1 and 2). There is one additional register called the serial
communications data register. This register when written to is the
transmit data register, and when read the receiver data register. Both
the transmit and receive data registers are double buffered.
The BAUD register contains two test bits and two divide control
registers that set the baud rate for the SCI system. The bits SCP control
the baud rate prescaler. This prescaler has the unlikely prescale value of
divide-by-13 when both bits are set. This value sets the maximum baud
rate to 9600 when the system is driven by an 8 MHz clock. With this
prescaler value, all of the standard baud rates from 9600 down to 150 are
available to the SCI. The second divider is comprised of SCR. The bit
patterns in these bits will select any power of two divisors between 1—
0
7
2 –and 128—2 . For our system, we will choose 9600 baud, which is
sufficiently slow that there should be few communications problems.
The code to set up this baud rate is as follows:
BAUD.SCP=3;
BAUD.SCR=0;
These lines of code must be added to the initialization portion of the
program to set up the baud rate to 9600 baud for the SCI system.
We will use the SCI system to read in the required motor speed
for the program started in the preceding section. Such a system must
be able to read in data through the SCI, but it must also echo the
same data back to the originating source to provide full duplex
operation. Therefore, both serial transmit and receive must be
implemented. With the above system, there is no serious need to
implement an interrupt driven system. The computer is clearly not
being used to its capacity, so we will add the SCI input and output
sequence to the applications portion of the code and feel safe that no
input data will ever be lost because of an overrun error. (An overrun
error occurs when a new input overwrites an old input before the old
input is processed.) Therefore, none of the bits in SCCR1 need be
changed from their reset value. In the SCCR2 register, there are two