You are on page 1of 21

Serial Communication

Basics of serial communication


Parallel: expensive - short distance fast no modulation Serial :cheaper long (two different cities by modem)slow

Packaging Data
Start and stop bits

In asynchronous transmission When there is no transfer the signal is high Transmission begins with a start (low) bit LSB first Finally 1 stop bit (high) Data transfer rate (baud rate) is stated in bps

2 methods, asynchronous and synchronous synchronous method transfers a block of data (characters) at a time asynchronous method transfers a single byte at a time Uses special IC chips called UART (universal asynchronous receiver-transmitter) and USART (universal synchronousasynchronous receiver-transmitter) 8051 chip has a built-in UART

RS232 pins

Data communication classification

Serial control (SCON) Register


1 7

SM0

SM1

SM2

REN
SM0 0 0 1

TB8

RB8

TI

RI

SM0 : mode specifier SM1 : mode specifier

SM1 MODE operation 0 0 shift register 1 1 8 bit UART 0 2 9 bit UART xtal/64) 1 3 9 bit UART

transmit rate fixed (xtal/12) variable (timer1) fixed (xtal/32 or

variable (timer1)

SM2 : used for multi processor communication REN : receive enable (by software enable/disable) TB8 : transmit bit8 RB8 : receive bit 8 TI : transmit interrupt flag set by HW after send , clear by SW

RI

: receive interrupt flag set by HW after received ,clear by SW

Mode of operation
Mode 0 : Serial data enters and exits through RxD TxD outputs the shift clock. 8 bits are transmitted/received(LSB first) The baud rate is fixed a 1/12 the oscillator frequency.

Application
Port expansion
8051
TXD RXD

clk Shift register data

Timing of send in mode 0


One machine cycle oscillator cycle

RXD (data) TXD (clock pulse)


MOV SCON,#0001xxxxB Wait: JNB TI,WAIT CLR TI MOV SBUF,A

MOV SCON,#0001xxxxB Wait: JNB RI,WAIT CLR RI MOV A,SBUF

Mode of operation
Mode 1
Ten bits are transmitted (through TxD) or received (through RxD)
(A start bit (0), 8 data bits (LSB first), and a stop bit (1) )

On receive, the stop bit goes into RB8 in SCON


the baud rate is determined by the Timer 1 overflow rate. Timer1 clock is 1/32 machine cycle (MC=1/12 XTAL)

Timer clock can be programmed as 1/16 of machine cycle Transmission is initiated by any instruction that uses SBUF as a destination register.

Mode of operation
Mode 2 :
Eleven bits are transmitted (through TxD), received (through RxD)
A start bit (0) 8 data bits (LSB first) A programmable 9th data bit and a stop bit (1)

On transmit, the 9th bit (TB8) can be assigned 0 or 1. On receive, the 9the data bit goes into RB8 in SCON. the 9th can be parity bit The baud rate is programmable to 1/32 or 1/64 the oscillator frequency in Mode 2 by SMOD bit in PCON register

Mode 3
Same as mode 2 But may have a variable baud rate generated from Timer 1.

Mode of operation

What is SMOD
Bit 7 of PCON register If SMOD=1 double baud rate

PCON is not bit addressable


How to set SMOD
Mov a, pcon Setb acc.7 Mov pcon,a

Power control register

Power control
A standard for applications where power consumption is critical two power reducing modes
Idle Power down

Baud rate in the 8051


serial communications of the 8051 with the COM port of the PC must make sure that the baud rate of the 8051 system matches the baud rate of the PC's COM port can use Windows HyperTerminal program

PC Baud Rates

Baud rate in the 8051


baud rate in the 8051 is programmable done with the help of Timer 1 relationship between the crystal frequency and the baud rate in the 8051 8051 divides the crystal frequency by 12 to get the machine cycle frequency XTAL = 11.0592 MHz, the machine cycle frequency is 921.6 kHz 8051's UART divides the machine cycle frequency of 921.6 kHz by 32 once more before it is used by Timer 1 to set the baud rate 921.6 kHz divided by 32 gives 28,800 Hz Timer 1 must be programmed in mode 2, that is 8-bit, auto-reload

Table 104

Timer 1 TH1 Register Values for Various Baud Rates

Example: With XTAL = 11.0592 MHz, find the TH1 value needed to have the following baud rates. (a) 9600 (b) 2400 (c) 1200

machine cycle frequency


= 11.0592 MHz / 12 = 921.6 kHz

Timer 1 frequency provided by 8051 UART


= 921.6 kHz / 32 = 28,800 Hz
(a) 28,800 / 3 = 9600 (b) 28,800 / 12 = 2400
(c) 28,800 / 24 = 1200

where -3 where -12


where -24

= FD (hex) = F4 (hex)
= E8 (hex)

You might also like