Professional Documents
Culture Documents
SL8lAL CCMMunlCA1lCn
lnLerrupLs
rof AmlL u ved
AssL rof Pead
LlecLrlcal Lnglneerlng ueparLmenL
Cardl college of Lnglneerlng and 1echnology
8a[koL ( Cu[araL)
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
1
aslcs of serlal communlcaLlon
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
Parallel: transIers eight bits oI data simultaneously over eight data
lines
expensive - short distance Iast
Serial : one bit at a time is transIerred over a single line
cheaper long distance-slow
Ser|a| transm|ss|on ara||e| transm|ss|on
wlres 8 wlres
roblem of lnLer symbol lnLerference
Small L C less bandwldLh and less daLa
raLe
S/n S/n Cl A8ALLLL More nolse less S/n
PlCP l1 8A1L uS0480MlLs/sec
!ISO
SI!O
asics oI serial communication
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
In simplex transmission such as with printers, computer only sends data.
II the data can be transmitted and received, it is a duplex transmission. Duplex can be
halI or Iull duplex, depending on whether or not the data transIer can be simultaneous.
NO MODULA1ION RLQUIRLD lOR SMALL DIS1ANCL. MODLM CAN BL USLD
lOR LONG DIS1ANCL.
aslcs of serlal communlcaLlon
W Serial data communication uses two methods:
Asynchronous and synchronous.
W The synchronous method transIers a block oI data
(characters) at a time , block oriented data transIer
W The ,synchronous method transIers a single byte at a time
W Special Ics. Character oriented data transIer, Iraming is
necessary.
W D@ (unlversal asynchronous 8ecelver LransmlLLer)
W DS@ (unlversal synchronousasynchronous 8ecelver
LransmlLLer)
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
ackag|ng Data
Start and stop b|ts
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
In asynchronous transmission when there is no transIer the signal is high
Transmission begins with a start (low) bit LS Iirst
Finally 1 stop bit (high) old systems had 2 bits as stop bit
For data integrity parity bit can also be included
Data transIer rate (baud rate) is stated in bps (the rate oI data transIer in serial data
communication is stated in bits per second) baud rate modem terminology no oI signal
change per second, many times in 1 signal change many bits can be transIerred, here
baudrate and bps are same.
8S S1AnuA8u
W 1 ls Lo 3v 0 ls + Lo +3v
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
W u1L(uA1A 1L8MnlAL LCulMLn1) CCM C8 1L8MlnAL
W uCL (uA1A CCMMunlCA1lCn LCulMLn1) MCuLM
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
W D@ (data term|na| ready) Jhen Lermlnal ls Lurned on lL sends ouL
slgnal u18 Lo lndlcaLe LhaL lL ls ready for communlcaLlon
W DS (data set ready) Jhen uCL ls Lurned on and has gone Lhrough
Lhe selfLesL lL asserL uS8 Lo lndlcaLe LhaL lL ls ready Lo
communlcaLe
W @S (request to send) Jhen Lhe u1L devlce has byLe Lo LransmlL lL
asserL 81S Lo slgnal Lhe modem LhaL lL has a byLe of daLa Lo
LransmlL
W C@S (c|ear to send) Jhen Lhe modem has room for sLorlng Lhe
daLa lL ls Lo recelve lL sends ouL slgnal C1S Lo u1L Lo lndlcaLe LhaL lL
can recelve Lhe daLa now
W DCD (data carr|er detect) 1he modem asserLs slgnal uCu Lo lnform
Lhe u1L LhaL a valld carrler has been deLecLed and LhaL conLacL
beLween lL and Lhe oLher modem ls esLabllshed
W (r|ng |nd|cator) An ouLpuL from Lhe modem and an lnpuL Lo a C
lndlcaLes LhaL Lhe Lelephone ls rlnglng lL goes on and off ln
synchronous wlLh Lhe rlnglng sound
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
MAx LlnL u8lvL8(8S11L)
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
8031 Serlal CommunlcaLlon
W The 8051 has a single Iull duplex (means it can transmit and receive data at a
time) serial port that can be used Ior either asynchronous or synchronous
communication.
W Facilities with 8051 Ior serial communications
S&F holds data
SCON control communication
PCON control data rate
RxD(P3.0) & TxD(P3.1)
W The port has 4 modes oI operation:
Mode 0: Synchronous at 1/12 oscillator Irequency.
Mode 1: 10 bit Asynchronous - variable baud rate.
Mode 2: 11 bit Asynchronous -1/32 OR 1/64 oI the oscillator Irequency.
Mode 3: 11 bit asynchronous - variable rate.
MODE 2 AND3- M<IPROCESSOR MODE
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
serlal communlcaLlon block dlagram
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
In the memory map we have serial buIIer special Iunction register (S&F) at
location 99H.
&nlike any other register in the 8051, S&F is in Iact two distinct registers -
the write-only register and the read-only register.
Transmitted data is sent out Irom the write-only register while received data is
stored in the read-only register.
There are two separate data lines, one Ior transmission (TXD)(P3.1) and one
Ior reception (RXD)(P3.0). ThereIore, the serial port can be transmitting data
down the TXD line while it is at the same time receiving data on the RXD line
I
N
1
L
R
N
A
L
B
U
S
\RI1L ONL\
,!ISO,
RLAD ONL\
,SI!O,
1XD
RXD
SBUl ,99h,
Byte
bit
bit
Byte
15
lRAMING
DLlRAMING
S&F register
W Data to be transmitted via the TXD line must be placed in S&F
register.
W S&F holds the byte oI data when it is received by 8051 RXD
line.
W MOV S&F, #45H - this sends the byte 45H down the serial
line
W MOV A, S&F - this takes whatever data was received by the
serial port and puts it in the accumulator
W Once byte is written in S&F, it is Iramed with the start and stop
bits and transIerred serially via the TXD pin.
W When the bits are received serially via RXD, the 8051 deIrames
it by eliminating the stop and start bits and then placed it in
S&F register.
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
Power confroI regisfer (PCOM)
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
W luLL MCuL
W CCn01
W CLCCk SlCnAL CA1Lu Cll 1C Cu nC1 1C Cn CPl L8lPL8AL
W Cu S1A1L lS 8LSL8vLu
W S C SJ A C1PL8 8LClS1L8S MAln1Aln uA1A
W C81 lnS PCLu LCClCAL S1A1uS
W ALL SLn 1
W Lxl1 l8CM luLL MCuL
AC1lvA1L LnALLu ln1L88u1
8LSL1
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
21
owerDown Mode
W PCON.1 1, causes power down mode
W The ALE and PSEN output are held low
W The reset that terminates Power Down
W Internal clock Irozen to entire Microcontroller (CORE &
PERIPHERAL)
W Program is not dead
W Cpu starts Irom next instruction where PD was invoked
W Port values are not changed
W Vcc can be reduced to 2V, but has to be restored beIore PD is exited.
W For 8051, active mode current 25mA, idle mode current 6.5mA and
power down mode current 100&A Ior 6v and 12MHz
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
Serlal conLrol (SCCn) 8eglsLer
8blL reglsLer used Lo program Lhe sLarL blL sLop blL and daLa blLs of daLa framlng 1CCn* (l1 Auu8LSSALL)
7 6 S 4 3 2 1 0
SM0 SM1 SM 8Ln 18 88 1l 8l
00 MCuL0
SPll1 8LClS1L8 MCuL
Jl1P llxLu Auu 8A1L
01 MCuL1
8l1 uA81 vA8lALL
Auu 8A1L
10 MCuL
l1 uA81
(MuL1l8CCLSSC8)
llxLu Auu 8A1L
11 MCuL
l1 uA81
(MuL1l8CCLSSC8)
vA8lALL Auu 8A1L
rogrammlng sLeps Lo
Lransfer daLa serlally ( ln
mode 1 )
MuL1l8CCLSSC8
CCMMunlCA1lCn l1
1 CnL? vALlu S1C
l1 CAn CLnL8A1L
ln1L88u1
MM
ln1 CLnL8A1Lu ll
l1 lS 1 nC
ln1L88u1
CLnL8A1Lu lC8
l10
M1
nC ln1L88u1
CLnL8A1Lu unLLSS
vALlu S1C l1
0 MCuL 0
8LCL1lCn
LnALLu l1
1 LnALL
8LCL1lCn
0 ulSALL
8LCL1lCn
xMl1 l1 8
1/0?
8CC8AM
ln MCuL
(MuL1l8CC
LSSC8
MCuL)
8LCLlvL l1 8
x lC8 M0
S1C l1 lC8
M1
l1 8 Cl uA1A
lC8 MCuL
(MuL1l8CCL
SSC8 MCuL)
18nASMl1
ln1L88u1
lLAC
1 Lnu Cl
l1 7 ln M0
Anu
8LG--G CI
S1C l1 ln
C1PL8 MCuL
0 CLLA8Lu
? 8CC8AM
A1 lS8
8LCLlvL
ln1L88u1
lLAC
1 Lnu Cl
l1 7 ln M0
Anu nI
W
@nCDGn
S1C l1 ln
C1PL8 MCuL
0 CLLA8Lu
? 8CC8AM
A1 lS8
12/12/2011 BE V (ELECTRCAL) ADVED 2010
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
SM2 : used for muIti processor communication - make it 0 for mode 0
REN : receive enabIe (by software enabIe/disabIe)
when high, it aIIows the 8051 to receive data on the RXD pin of the 8051
8051 in simuItaneous transmit and receive mode REN must be set to 1
REN = 0 means receiver is disabIed
TB8 : transmit bit8 - not wideIy used - make it 0 - used for seriaI mode 2 and 3
RB8 : receive bit 8- not wideIy used - make it 0 - in mode 1 this bit gets a copy of
the stop bit, when 8 bit data is received . AIso used for mode 2 and 3.
TI : transmit interrupt fIag set by H/W after send , cIear by SW
when 8051 finishes the transfer of the 8 - bit character, it raises the TI fIag to
indicate that it is ready to transfer another byte. TI is raised at the beginning
of the stop bit.
RI : receive interrupt fIag set by HW after received ,cIear by SW
when 8051 receives data seriaIIy via RXD it gets rid of the start and stop bit
and pIaces the byte in SBUF register. Then it raises the RI bit to indicate that
the byte has been received and shouId be picked up before it is Iost. RI is
raised haIfway through the stop bit.
RI =0, NEXT BYTE CAN BE TRANSFERRED TO SBUF. FAILING TO MAKE RI =0, NEXT BYTE
WILL BE LOST.
IF DATA IS READ BEFORE RI =1, GARBAGE DATA READ,
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
W SL8lAL uA1A ln1L88u1
W SLCJ 8CCLSS MAn? ms/byLe
W Sr daLa flags ln scon saves Llme
W 1x under program conLrol 8x random and unpredlcLable
W rogram musL read 8l/1l whenever serlal lnLerrupL ls acLlvaLe
W uA1A 18AnSMlSSlCn
W SLarLs when daLa wrlLLen ln Sul
W Jhen all blLs are Lransferred Sul ls empLy and 1l 1
W Jhen 1l1 anoLher daLa can be loaded ln Sul (JPA1 ll nC1 JAl1Lu lC8 1l 1?)
W uA1A 8LCL1lCn
W 8Ln 1(SCCn4)
W MCuL 0 8l 0 Jhen daLa recelved 8l 1 prog reads Sul and clears 8l
W M1 8l 1 uaLa recepLlon over and daLa may be read ln 8l 0 before lasL blL ls recelved
oLherwlse lncomlng daLa wlll be losL
W lncomlng daLa Lransferred Lo Sul only afLer lasL blL of daLa ls recelved revlous daLa can be
read from Sul whlle new daLa ls recelved
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
RI
1I
SLRIAL IN1R ,0023h,
16
Mode 0 of operaLlon
W Mode 0 slmply a shlfL reglsLer
Serlal daLa enLers and exlLs
Lhrough 8xu
1xu ouLpuLs Lhe shlfL clock
8 blLs are LransmlLLed/recelved
(LS flrsL)
1he baud raLe ls flxed aL 1/1
Lhe osclllaLor frequency
W AppllcaLlon
orL expanslon
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
Mode 0 of operaLlon
W As can be seen in the diagram the terms TXD and RXD are
misleading in mode 0.
W TXD serves as the clock while RXD is used Ior both receiving
and transmitting data.
W In mode 0, the serial port is only halI duplex; it cannot transmit
and receive data at the same time because the same line (RXD)
is being used Ior both transmit and receive.
W The serial port in mode 0 is an example oI synchronous
communic,tion; the clock signal is sent with the data on the
TXD line. TXD pulses at the same Irequency as the machine
cycle means TXD runs at 1/12th the Irequency oI the system
clock.
W II we are using a 12MHz system clock, then the Irequency oI
TXD is 1MHz, which implies its cycle length is 1us.
ThereIore, each bit is active on the RXD line Ior 1us. To shiIt
the entire 8-bit word along RXD takes 8us.
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
ode I of operofion
W Mode 1
Ten bits are transmitted (through TxD) or received (through RxD)
(A start bit (0), 8 data bits (LS Iirst), and a stop bit (1) )
On receive, the stop bit goes into R8 in SCON
the baud rate is determined by the Timer 1 overIlow rate.
Timer1 clock is 1/32 machine cycle (MC1/12 XTAL)
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
1imer clock can be programmed as 1,16 o machine cycle
1ransmission is initiated by any instruction that uses SBUl as a destination
register.
Sett|ng the Ser|a| ort 8aud ate
W serial ports baud rate setting is required Ior modes 1 and 3.
W The aud Rate is determined based on the oscillators Irequency when
in mode 0 and 2.
W In mode 0, the baud rate is always the oscillator Irequency divided by
12. This means iI youre crystal is 11.059Mhz, mode 0 baud rate will
always be 921,583 baud.
W In mode 2 the baud rate is always the oscillator Irequency divided by
64, so a 11.059Mhz crystal speed will yield a baud rate oI 172,797.
baud rate can also be doubled by smod 1
W In modes 1 and 3, the baud rate is determined by how Irequently timer
1 overIlows.
W The more Irequently timer 1 overIlows, the higher the baud rate. There
are many ways one can cause timer 1 to overIlow at a rate that
determines a baud rate, but the most common method is to put timer 1
in 8-bit auto-reload mode (timer mode 2) and set a reload value (TH1)
that causes Timer 1 to overIlow at a Irequency appropriate to generate
a baud rate.
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
Sett|ng the Ser|a| ort 8aud ate
W To determine the value that must be placed in TH1 to generate a given baud
rate, we may use the Iollowing equation (assuming PCON.7 (SMOD) is
clear). Load TMOD with 0010 0000 20H timer1 in autoreload mode(m2)
W TH1 256 ((2
SMOD
/32)* (I
Crystal
/ 12)) / aud)
W TH1 256 - ((I
Crystal
/ 384) / aud)
W TH1 256 - ((I
Crystal
/ 384) / aud)
TH1 256 - ((11059200 / 384) / 9600 )
TH1 256 - ((28,800) / 9600)
TH1 256 3 253 FD H
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
1
rogramm|ng steps to transfer data ser|a||y
( |n mode 1 )
1. TMOD Reg is loaded with 20H (timer 1 in mode 2) to set the baud
rate
2. TH1 is loaded with the count Ior speciIic baud rate
3. SCON with 50H iI simultaneous transmit and receive operations are
required else only Ior transmit load 40 H Ior mode 1.
4. Tr1 is set to start time -1
5. TI is cleared by CLR TI means make it 0 during the starting
6. The character byte to be transIerred serially is written into S&F.
7. TI Ilag is to be monitored to iI the character has been transIerred
completely.
8. To transIer the next character go to step 5Serial control (SCON)
Register 8-bit register used to pro...
9. TMOD
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
W JrlLe a program for Lhe 8031 Lo Lransfer leLLer
A" serlally aL 4800 baud conLlnuously
W So|ut|on
MCv 1MCu#0P Llmer 1mode (auLo
reload)
MCv 1P1#6 4800 baud raLe
MCv SCCn#30P 8blL 1 sLop 8Ln enabled
SL1 181 sLarL Llmer 1
ACAln MCv Sul#"A" leLLer A" Lo Lransfer
PL8L !n 1lPL8L walL for Lhe lasL blL
CL8 1l clear 1l for nexL char
S!M ACAln keep sendlng A
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
W JrlLe a C program for 8031 Lo Lransfer Lhe leLLer A" serlally aL 4800
baud conLlnuously use 8blL daLa and 1 sLop blL
W So|ut|on
#lnclude reg31h
vold maln(vold)
Ser1x('?')
Ser1x('L')
Ser1x('S')
1MCu 0x0 // conflgure Llmer1 for Mode operaLlon for Lhe correcL baud raLe
1P1 0xlu // 600 bps for 1103 MPz clock
1CCn 0x40 // SLarL Llmer 1 by seLLlng 181 1
SCCn 0x30 // SeL Serlal lC Lo recelve and normal mode
8l0 //8ecelve lnLerrupL llag ls cleared
1l0 //1x lnLerrupL flag ls cleared
unslgned char z
unslgned char Mess1normal Speed"
unslgned char MessPlgh Speed"
1MCu0x0 //use 1lmer 1 mode
1P10xll //8800 for normal
SCCn0x30
1811 //sLarL Llmer
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
lf(M?SJ0)
for (z0z1z++)
else
10
1MCu 0x01
1L0 L0lsb
1P0 L0msb
LA 1
L10 1
1801
C 1
wlk 1
? 0
8 0
nwlk 0
whlle(1)
1L0 t0lsb,
1l0 t0msb,
count--,
i,count00,
G 0,
wlk 0,
\ 1,
nwlk 1,
}
i,count500,
\ 0,
R 1,
}
i,count2000,
R 0,
nwlk 0,
G1,
wlk1,
count0,
}
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010
12,12,2011 BL VI ,LLLC1RICAL, ADVLD 2010