Vous êtes sur la page 1sur 36

Computer Engineering - Suranaree University of Technology

Chapter 10

8051 Serial Communication


Computer Engineering - Suranaree University of Technology

Outlines
• Contrast and compare serial versus parallel
communication
• List the advantages of serial communication over
parallel
• Explain serial communication protocol
• Contrast synchronous versus asynchronous
communication
• Contrast half-versus full-duplex transmission
Computer Engineering - Suranaree University of Technology

• Explain the process of data framing


• Describe data transfer rate and bps rate
• Define the RS232 standard
• Explain the use of the MAX232 and MAX233 chips
• Interface the 8051 with an RS232 connector
• Discuss the baud rate of the 8051
• Describe serial communication features of the 8051
• Program the 8051 for serial data communication
Computer Engineering - Suranaree University of Technology

Heading
1.Basic of Serial Communications
- Parallel VS Serial
- Simplex Half- and Full duplex
- Asynchronous Serial
- Data transfer rate
- RS232 Standard
2.8051 Connection to RS232
- MAX232 Connection
3.8051 Serial Port Programming
- Frame  SCON
- Baud  Timer(TMOD,TR1,TH1,PCON)
Computer Engineering - Suranaree University of Technology

H1. Basics of serial communication

Figure 10–1 Serial versus Parallel Data Transfer


Computer Engineering - Suranaree University of Technology

Figure 10–2:Simplex, Half-, and Full-Duplex Transfers


Computer Engineering - Suranaree University of Technology

Start and stop bits

Figure 10–3 Framing ASCII “A” (41H)


Computer Engineering - Suranaree University of Technology

RS232 pins

Figure 10–4 RS232 Connector DB-25


Computer Engineering - Suranaree University of Technology

Data communication classification

Figure 10–5:DB-9 9-Pin Connector

Figure 10–6:Null Modem Connection


Computer Engineering - Suranaree University of Technology

H2.8051 Connection to RS232

RxD and TxD pins in the 8051

TxD pin 11 of
the 8051 (P3.1)
RxD pin 10 of
the 8051 (P3.0)
Computer Engineering - Suranaree University of Technology

MAX232

Figure 10–7: (a) Inside MAX232 and (b) its Connection to the 8051 (Null Modem)
Computer Engineering - Suranaree University of Technology

MAX233

Figure 10–8:(a) Inside MAX233 and (b) Its Connection to the 8051 (Null Modem)
Computer Engineering - Suranaree University of Technology

H3.8051 Serial Port Programming

-Frame
SCON
-Baud
Timer(TMOD,TR1,TH1)
SMOD in PCON Reg.

Table 10–3: PC Baud Rates


Computer Engineering - Suranaree University of Technology

Baud Rate Calculation


1.Using Timer1 Mode2 in Serial Mode 1,3

SMOD1
2 x Oscillater Frequency
BaudRate =
32 x 12 x [256 - (th1)]
9600 @18.432MHz  SMOD1=0, TH1=251(FBH)
9600 @11.0592MHz  SMOD1=0, TH1=253(FDH)

MOV SCON,#050H ; Serial Port Mode 3


ANL PCON,#7FH ; SMOD 0(SMOD in PCON.7)
MOV TMOD,#20H ; Timer1 Mode2
MOV TH1,#0FDH ; Reload value for desired baud
SETB TR1 ; Turn on Timer1

http://www.intel.com/design/mcs51/applnots/270490.htm
Computer Engineering - Suranaree University of Technology

Baud Rate Calculation(2)


2.Using Timer2 in Serial Mode 1,3

Oscillater Frequency
Buad rate=
32 x [65536 - (RCAP2H,RCAP2L)]
9600 @18.432MHz  RCAP2H,RCAP2L = 65476 = FFC4H
9600 @11.0592MHz  RCAP2H,RCAP2L = 65500 = FFDCH

MOV SCON,#01010000B ; Mode1 Serial Port


MOV RCAP2H,#0FFH ; Reload values for desired
MOV RCAP2L,#0DCH ; baud rate 9600@11.0592
MOV T2CON,#00110100B ; Timer 2 as baud rate generator
; and turn on Timer 2

http://www.intel.com/design/mcs51/applnots/270490.htm
Computer Engineering - Suranaree University of Technology

Example10.1
Computer Engineering - Suranaree University of Technology

Table 10–4:Timer 1 TH1 Register Values for Various Baud Rates


Computer Engineering - Suranaree University of Technology

SBUF register
MOV SBUF,#’D’ ;load SBUF=44H, ASCII for ‘D’
MOV SBUF,A ;copy accumulator into SBUF
MOV A,SBUF ;copy SBUF into accumulator
Computer Engineering - Suranaree University of Technology

SCON (Serial control) register


Computer Engineering - Suranaree University of Technology

SM0,SM1

SM0 and SM1 are D7 and D6 of the SCON


SM0 SM1
0 0 Serial Mode 0
0 1 Serial Mode 1,8 bit data,
1 stop bit, 1 start bit
1 0 Serial Mode 2
1 1 Serial Mode 3
Computer Engineering - Suranaree University of Technology

Programming the 8051 to Tx data


Tx_Byte: MOV SBUF,A
JNB TI,$
CLR TI

Example10.2
Computer Engineering - Suranaree University of Technology

Example10.3
Computer Engineering - Suranaree University of Technology

Programming the 8051 to Rx data


Rx_Byte: JNB RI,$
MOV A,SBUF
CLR RI

Example10.4
Computer Engineering - Suranaree University of Technology

Example10.5
Computer Engineering - Suranaree University of Technology
Computer Engineering - Suranaree University of Technology
Computer Engineering - Suranaree University of Technology

Doubling the baud rate in the 8051

1. To use a higher frequency crystal


2. To change a bit in the PCON register
D7 D0
SMOD -- -- -- GF1 GF0 PD IDL

MOV A,PCON ; Place a copy of PCON in Acc


SETB Acc.7 ; Make D7=1
MOV PCON,A ; Now SMOD=1 without
; Changing any other bits
Computer Engineering - Suranaree University of Technology

Timer1 Baud rate Generate


SMOD1
2 x Oscillater Frequency
BaudRate =
32 x 12 x [256 - (th1)]

Table 10–5: Baud Rate Comparison for SMOD = 0 and SMOD = 1


Example10.6
Computer Engineering - Suranaree University of Technology

Lab7Srl1.ASM: Send ASCII A with 9600 bps


Computer Engineering - Suranaree University of Technology

Lab7Srl2.ASM: Receive and Show Data Input


Computer Engineering - Suranaree University of Technology

Lab7Srl3.ASM: Using Include Subroutine


Computer Engineering - Suranaree University of Technology

System.Sub: Subroutine Program


Computer Engineering - Suranaree University of Technology

System.Sub: Subroutine Program(2)


Computer Engineering - Suranaree University of Technology

System.Sub: Subroutine Program(3)


Computer Engineering - Suranaree University of Technology

System.Sub: Subroutine Program(4)

Vous aimerez peut-être aussi