Writing to the Serial Port

Table 9−6. Baud Rate Settings for Timer 2.

Baud Rate

 

 

 

33MHz clk

25MHz clk

11.0592MHz clk

 

 

 

 

 

 

 

 

 

(kb/s)

C/T2

RCAP2H

RCAP2L

RCAP2H

RCAP2L

RCAP2H

RCAP2L

19.2

0

 

FFH

EEH

FFH

F2H

FFH

FAH

9.6

0

 

FFH

CAH

FFH

D7H

FFH

EEH

4.8

0

 

FFH

95H

FFH

AFH

FFH

DCH

2.4

0

 

FFH

29H

FFH

5DH

FFH

B8H

1.2

0

 

FEH

52H

FEH

BBH

FFH

70H

1.2

0

 

FCH

A5H

FDH

75H

FEH

E0H

9.4 Writing to the Serial Port

Once the serial port has been properly configured as explained previously, the serial port is ready to be used to send and receive data. If you think configuring the serial port was easy, using the serial port will be even easier.

To write a byte to the serial port, simply write the value to the SBUF0 (99H) SFR. For example, sending the letter A to the serial port is accomplished as easily as:

MOV SBUF0,#’A’

Upon execution of the above instruction, the MSC1210 will begin transmitting the character via the serial port. Obviously, transmission is not instanta- neous—it takes a measurable amount of time to transmit the eight data bits that make up the byte, along with its start and stop bits—and because the MSC1210 does not have a serial output buffer, you need to be sure that a char- acter is completely transmitted before trying to transmit the next character.

The MSC1210 lets you know when it is done transmitting a character by setting the TI bit in SCON. When this bit is set, the last character has been transmitted and the next character, if any, may be sent. Consider the following code segment:

CLR TI

;Be sure the

bit is

initially clear

MOV

SBUF,#’A’

;Send the letter

‘A’ to

the serial port

JNB

TI,$

;Pause until

the

RI

bit

is set.

The above three instructions transmit a character and wait for the TI bit to be set before continuing. The last instruction says jump if the TI bit is not set to $. The $ character (in most assemblers), means the same address of the cur- rent instruction. Therefore, the MSC1210 will pause on the JNB instruction un- til the TI bit is set (upon successful transmission of the character).

Serial Communication

9-15

 

Page 105
Image 105
Texas Instruments MSC1210 manual Writing to the Serial Port, 6. Baud Rate Settings for Timer