USER'S GUIDE

APPLICATION: SERIAL PORT

INITIALIZATION

The serial port can provide either synchronous or asynchronous serial communication. This note demon- strates how to initialize the serial port and includes an example showing how to perform asynchronous com- munication with a PC COM port.

A typical goal of microcontroller to PC communication is to transfer stored data from the nonvolatile RAM. This example will show how to move 256 bytes from NV RAM to the PC via the serial port. Once the 256 bytes have been received by the PC, it will send confirmation. For this example, the confirmation code will be A5h. The Microcontroller will run at 11.0592 MHz, a common crys-

SERIAL I/O OPERATING MODES

MODE

SYNC/ASYNC

BAUD CLOCK

MODE 0

SYNC

12 tCLK

MODE 1

ASYNC

Timer 1

 

 

Overflow

MODE 2

ASYNC

32 tCLK or

 

 

64 tCLK

MODE 3

ASYNC

Timer 1

 

 

Overflow

tal choice. This example will demonstrate both 9600 and 19,200 bps. A typical application has some form of error checking built into the data, so no parity is required. This code will therefore run at 8N1 or 8 bits, no parity, 1 stop bit. This is a common selection for PC terminal emulator software. Thus the setup summary is as follows:

Communication type :

Asynchronous

Baud Rate :

9600, 19200

Bits per word :

8

Stop bits :

1

As shown in the following table, this most closely corre- sponds to Serial Mode 1.

DATA BITS

START/STOP

9TH DATA BIT

 

 

FUNCTION

8

None

None

8

1 Start

None

 

1 Stop

 

9

1 Start

0, 1, or parity

 

1 Stop

 

9

1 Start

0, 1, or parity

 

1 Stop

 

The Serial Port is controlled by the SCON register. Serial Interrupts will also be used. These are controlled by IE and IP. The setup for each SFR is shown below. In addition, Mode 1 is associated with Timer 1, which is controlled by TCON and TMOD.

Mode 1 is selected using the SCON register. The table from the SCON register shown below indicates that Mode 1 is selected by choosing the value SM0 = 0 and SM1 = 1.

SMO

SM1

MODE

FUNCTION

WORD LENGTH

BAUD CLOCK

 

 

 

 

 

 

0

0

Mode 0

Synchronous

8 bits

12 tCLK

0

1

Mode 1

Asynchronous

10 bits

Timer 1 Overflow

1

0

Mode 2

Asynchronous

11 bits

32 or 64 tCLK

1

1

Mode 3

Asynchronous

11 bits

Timer 1 Overflow

050396 119/173

120

Page 120
Image 120
Mitsubishi DS907x SIP, DS5000TK manual Application Serial Port Initialization, Serial I/O Operating Modes