MS51
Nov. 28, 2019
Page
367
of 491
Rev 1.00
MS51
32K
SE
RIES
TE
CHNICAL RE
F
EREN
CE MA
N
UAL
Note:
Timer 1 should configured as a timer in auto-reload mode (Mode 2).
Table 6.9-1 Serial Port UART0 Mode / baudrate Description
Mode
Frame
Bits
SM0_1 / SM1_1
(S1CON[7:6])
SMOD_1
(T3CON[7])
Baud Rate
0
8
00
-
FSYS divided by 12
1
10
01
0
Timer 3
RL3)
RH3
(256
-
65536
scale
-
Pre
F
32
1
SYS
1
Timer 3
RL3)
RH3
(256
-
65536
scale
-
Pre
F
16
1
SYS
2
11
10
0
FSYS divided by 64
1
FSYS divided by 32
3
11
11
0
Timer 3
RL3)
RH3
(256
-
65536
scale
-
Pre
F
32
1
SYS
1
Timer 3
RL3)
RH3
(256
-
65536
scale
-
Pre
F
16
1
SYS
Table 6.9-2 Serial Port UART1 Mode / baudrate Description
Sample code: we list the most popular UART setting Mode 1 initial step as following
:
Serial port 0 (
UART0
) use
timer 1
as baudrate generator: Formula is
TH1
-
256
F
16
1
SYS
SCON = 0x50;
//UART0 Mode1,REN=1,TI=1
TMOD |= 0x20;
//Timer1 set to Mode2 auto reload mode (must)
PCON |= 0x80;
//UART0 Double Rate Enable
CKCON |= 0x10;
//Timer 1 as clock source
T3CON &= 0xDF;
//Timer1 as UART0 clock source
TH1 =
value
;
TR1=1;
Serial port 0 (
UART0
) use
Timer 3
as baudrate generator: Formula is
RL3)
RH3
(256
-
65536
scale
-
Pre
F
16
1
SYS
SCON = 0x50;
//UART0 Mode1,REN=1,TI=1
PCON |= 0x80;
//UART0 Double Rate Enable
T3CON &= 0xF8;
//(Prescale=1)
T3CON |= 0x20;
//UART0 baud rate clock source = Timer3
RH3 =
value high byte