0% found this document useful (0 votes)
3 views

Microcontroller & Applications - ModuleIII-2023

This document discusses the 8051 microcontroller's interrupts, timers, and serial communication. It covers the types and handling of interrupts, the TMOD and TCON registers for timer operations, and special function registers for serial communication. Additionally, it explains the differences between timers and counters, and the configuration of interrupt priorities and modes.

Uploaded by

amal0072k5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Microcontroller & Applications - ModuleIII-2023

This document discusses the 8051 microcontroller's interrupts, timers, and serial communication. It covers the types and handling of interrupts, the TMOD and TCON registers for timer operations, and special function registers for serial communication. Additionally, it explains the differences between timers and counters, and the configuration of interrupt priorities and modes.

Uploaded by

amal0072k5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 91

8051 INTURRUPTS ,TIMERS &

SERIAL COMMUNICATION
Module III

Baiju.G.S
Lecturer in Electronics Eng
CO3 : Explain interrupts, timer and serial communication in 8051.

M3.01 : Explain concept, types, priority, Registers for Interrupts and


handling of interrupts. 4 Understanding

M3.02 : Explain TMOD register and timer operating modes. 4 Understanding

M3.03: Illustrate TCON register and time delay calculation for Timer. 3
Understanding

M3.04 : Illustrate special function registers for serial communication. 3


Understanding
• Contents:
• Interrupts, Timers, Serial communication. 8051 Interrupts:
Concept, Types, Interrupt service routine (ISR), IE register,
Steps in executing an interrupt, Interrupt priority, IP register.

• Timer: TMOD register, Timer operating modes, TCON


register, Time Delay calculation.

• Basics of serial communication, Baud rate, 8051 connections


to RS232 connector, SBUF register, SCON register and
Different serial data transmission modes in 8051. PCON
register.

3/15/2023 Baiju G S 3
8051
Interrupts

3/15/2023 Baiju G S 4
3/15/2023 Baiju G S 5
Interrupts Programming

• A single microcontroller can serve several


devices.
• There are two ways to do that:
– interrupts
– polling.
• The program which is associated with the
interrupt is called the interrupt service routine
(ISR) or interrupt handler.

3/15/2023 Baiju G S 6
3/15/2023 Baiju G S 7
Steps in executing an interrupt
• Finish current instruction and saves the PC on stack.
• Jumps to a fixed location in memory depend on type
of interrupt

• Starts to execute the interrupt service routine until


RETI (return from interrupt)

• Upon executing the RETI the microcontroller returns


to the place where it was interrupted. Get pop PC
from stack

3/15/2023 Baiju G S 8
Interrupt Sources
• Original 8051 has 6 sources of interrupts
• - Reset
– Timer 0 overflow
– Timer 1 overflow
– External Interrupt 0
– External Interrupt 1
– Serial Port events (buffer full, buffer empty, etc)

• Enhanced version has 22 sources


– More timers, programmable counter array,
ADC, more external interrupts, another serial
port (UART) 3/15/2023 Baiju G S 9
Interrupt vector Table
• When an interrupt is invoked, the
microcontroller runs the interrupt service
routine. For every interrupt, there is a
fixed location in memory that holds the
address of its ISR. The group of memory
locations set aside to hold the addresses
of ISRs is called the interrupt vector table

3/15/2023 Baiju G S 10
3/15/2023 Baiju G S 11
Redirecting the 8051 from the
Interrupt Vector Table at Power-up
• Upon reset, all interrupts are disabled (masked),
meaning that none will be responded to by the
microcontroller if they are activated. The interrupts
must be enabled by software in order for the
microcontroller to respond to them. There is a
register called IE (interrupt enable) that is
responsible for enabling (unmasking) and disabling
(masking) the interrupts. Figure below shows the IE
register. Note that IE is a bit-addressable register.

3/15/2023 Baiju G S 12
Interrupt Enable (IE) register
All interrupt are disabled after reset
We can enable and disable them bye IE
Steps in enabling an interrupt

• To enable an interrupt, we take the following


steps:
• .1. Bit D7 of the IE register (EA) must be set to
high to allow the rest of register to take effect.

• 2. If EA = 1, interrupts are enabled and will be


responded to if their corresponding bits in IE
are high. If EA = 0, no interrupt will be
responded to, even if the associated bit in the
IE register is high.
Enabling and disabling an interrupt

by bit operation

SETB EA SETB IE.7 ;Enable All


SETB ET0 SETB IE.1 ;Enable Timer0 ovrf
SETB ET1 SETB IE.3 ;Enable Timer1 ovrf
SETB EX0 SETB IE.0 ;Enable INT0
SETB EX1 SETB IE.2 ;Enable INT1
SETB ES SETB IE.4 ;Enable Serial port

by MOV instruction


Recommended in the first of program
MOV IE, #10010110B
Interrupt Priorities
• What if two interrupt sources interrupt at the same
time?
• The interrupt with the highest PRIORITY gets serviced
first.
• All interrupts have a power on default priority order.
1. External interrupt 0 (INT0)
2. Timer interrupt0 (TF0)
3. External interrupt 1 (INT1)
4. Timer interrupt1 (TF1)
5. Serial communication (RI+TI)
• Priority can also be3/15/2023
set to “high” orBaiju
“low”
G S by IP reg. 16
Interrupt Priorities (IP) Register

--- --- PT2 PS PT1 PX1 PT0 PX0

IP.7: reserved
IP.6: reserved
IP.5: timer 2 interrupt priority bit(8052 only)
IP.4: serial port interrupt priority bit
IP.3: timer 1 interrupt priority bit
IP.2: external interrupt 1 priority bit
IP.1: timer 0 interrupt priority bit
IP.0: external interrupt 0 priority bit

3/15/2023 Baiju G S 17
Interrupt Priorities Example
--- --- PT2 PS PT1 PX1 PT0 PX0

• MOV IP , #00000100B or SETB IP.2 gives priority order


1. Int1
2. Int0
3. Timer0
4. Timer1
5. Serial
• MOV IP , #00001100B gives priority order
1. Int1
2. Timer1
3. Int0
4. Timer0
5. Serial

3/15/2023 Baiju G S 18
Interrupt inside an interrupt
--- --- PT2 PS PT1 PX1 PT0 PX0

 A high-priority interrupt can interrupt a low-


priority interrupt
 All interrupt are latched internally
 Low-priority interrupt wait until 8051 has
finished servicing the high-priority interrupt

3/15/2023 Baiju G S 19
8051
Timers / Counters

3/15/2023 Baiju G S 20
The 8051 has two counters/timers which can be used
either as timer to generate a time delay or as counter to
count events happening outside the microcontroller.

* The 8051 has two timers: timer0 and timer1.

* They can be used either as timers or as


counters, ie Interval timer and counter

* Both timers are 16 bits wide


Since 8051 has an 8-bit architecture, each 16-bits timer is
accessed as two separate registers of low byte and high
byte
Two 16-bits timers are
• T0
• T1

 Maximum value is 65536

 Initial state can be set by user

5
Difference between a Timer and a Counter

A timer uses the frequency of the internal clock, and


generates delay.
Timer counts machine cycle

A counter uses an external signal to count pulses


Counts events as a result of falling slope of external
signal

Timer mode and counter mode are relative to


machine cycle
Timer Vs Counter
Differences

 Timer
• Input from internal system clock
 Counters:
• Show the number of events on registers
• External input from T0 input pin (P3.4) for Counter 0

• External input from T1 input pin (P3.5) for Counter 1


Pin Description of the 8051
P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0)
P1.2 3 38 P0.1(AD1)
P1.3 4 37 P0.2(AD2)
P1.4 5 36 P0.3(AD3)
P1.5 6 35 P0.4(AD4)
P1.6 7 8051 34 P0.5(AD5)
P1.7 8 33 P0.6(AD6)
RST 9 32 P0.7(AD7)
(RXD)P3.0 10 31 EA/VPP
(TXD)P3.1 11 30 ALE/PROG
(INT0)P3.2 12 29 PSEN
(INT1)P3.3 13 28 P2.7(A15)
(T0)P3.4 14 27 P2.6(A14)
(T1)P3.5 15 26 P2.5(A13)
(WR)P3.6 16 25 P2.4(A12)
(RD)P3.7 17 24 P2.3(A11)
XTAL2 18 23 P2.2(A10)
XTAL1 19 22 P2.1(A9)
GND 20 21 P2.0(A8) 

3/15/2023 Baiju G S 25
Timer/Counter
Special Function Registers

 Timers/Counters can be operated by user with


special function registers

 T0 and T1 share two SFRs: TMOD and TCON

 Each timer has also two registers dedicated to


itself: TH0/TL0 and TH1/TL1
Timer 0 & 1 Registers
Timer 0 & 1 Registers cont..

• Accessed as low byte and high byte


– The low byte register is called TL0/TL1
– The high byte register is called TH0/TH1
– Accessed like any other register
MOV TL0,#4FH
MOV R5,TH0

3/15/2023 Baiju G S 28
TMOD Register

• Both timers 0 and 1 use the same register,


called TMOD (timer mode), to set the various
timer operation modes

– TMOD is a 8-bit register


• The lower 4 bits are for Timer 0
• The upper 4 bits are for Timer 1
– In each case, the lower 2 bits are used to set the
timer mode
– The upper 2 bits to specify the operation
3/15/2023 Baiju G S 29
 TMOD (Timer Mode Register) is a non-bit-
addressable, 8-bit register:
C/T
•  C/T bit decides about timer type:
interval timer or counter

• f C/T = 0, it is used as a timer for time delay


generation. The clock source for the time
delay is the crystal frequency of the 8051.
• If C/T = 1, it is used as a counter for event
counters to count events happening outside
the microcontroller
3/15/2023 Baiju G S 31
M0 and M1

 M0 and M1 bits are used to set timer


mode (the same for Timer0 and Timer1)
 8051 delivers 4 timer modes:
M1 M0 Mode Description
0 0 Mode 0 13-bit timer

0 1 Mode 1 16-bit timer

1 0 Mode 2 8-bit auto reload

1 1 Mode 3 Split timer mode


GATE

• Timers of 8051 do starting and stopping by


either software or hardware control
– In using software to start and stop the timer where
GATE=0
• The start and stop of the timer are controlled by way of
software by the TR (timer start) bits TR0 and TR1 in the
TCON register
• The SETB instruction starts it, and it is stopped by the CLR
instruction
– These instructions start and stop the timers as long as GATE=0 in
the TMOD register

3/15/2023 Baiju G S 34
GATE (cont.)
• The hardware way of starting and
stopping the timer by an external source
is achieved by making GATE=1 in the
TMOD register

3/15/2023 Baiju G S 35
TCON Register

• TCON (timer control) register is an 8-bit


register

3/15/2023 Baiju G S 36
3/15/2023 Baiju G S 37
• TCON.7 - TF1 Timer1 over flow flag
Set when timer rolls from all 1s to 0. Cleared
When the processor vectors to execute interrupt
service routine Located at program address
001Bh.
• TCON.6- TR1 Timer 1 run control bit
Set to 1 by programmer to enable timer to
count; Cleared to 0 by program to halt timer.
. TCON.5 -TF0 Timer 0 over flow flag. Same as TF1.
. TCON.4- TR0 Timer 0 run control bit. Same as TR1
3/15/2023 Baiju G S 38
• TCON.3 -IE1 External interrupt 1 Edge flag
Not related to timer operations.
. TCON.2 -IT1 External interrupt1 signal type control bit
Set to 1 by program to Enable external
interrupt 1 to be triggered by a falling edge signal.
Set To 0 by program to enable a low level signal
on external interrupt1 to generate an interrupt.
. TCON.1 IE0 External interrupt 0 Edge flag
Not related to timer operations.
. TCON.0 – IT0 External interrupt 0 signal type control bit
Same as IT1
3/15/2023 Baiju G S 39
Timer/Counter
Special Function Registers-TCON

 TR0 and TR1 are set by user to turn on (or turn


off) Timer0 or Timer1:
• TR=0 – turn off
• TR=1 – turn on
 TF0 and TF1 are Timer Flags informing about
overflow (then TF=1 and interrupt could be
activate if it’s set, should be cleaned)
• TCON register is a bit-addressable register

3/15/2023 Baiju G S 41
Timer modes
• The timers may operate in one of four modes:
• Mode 0
• Mode 1
• Mode 2
• Mode 3

3/15/2023 Baiju G S 42
Timer Modes
Mode 0
 Mode 0 is identical for Timer0 and Timer1
In this mode, the timers act as 13 bit counters. It is largely
meant for providing compatibility with an older
microcontroller from intel (8048). This mode is practically
never used in fresh designs. Except for the counter size,
this mode is identical to mode 1.
 Timers work as 13-bit counters, an interrupt is
generated when counter overflows. It takes
8192 input pulses to generate the next
interrupt
 Timers use 8 bits of THi and 5 lower bits of TLi
 After timer overflows TFi (Timer Flag in TCON)
is set, an interrupt occurs Where i=0 or 1
Timer Modes
Mode 0

 Structure of Timer1 in mode 0:


Mode 1
In this mode, the timers are 16 bits in size. This is a
commonly used mode. It is common to configure the
timer to cause an interrupt when it overflows. The
interrupt routine then reloads the timer.

Similar to mode 0

 Timers use 8 bits of THi and 8 bits of Tli

 Timer is a 16-bit counter, it takes 65536 input


pulses to generate the next interrupt

 Improved capacity
Timer Modes
Mode 1

 Structure of Timer0 in mode 1:


Mode 2
This mode provides an 8 bit counter with auto-reload.
It uses the high byte of the count register to store the
count value and the low byte as the actual counter. The
counter is automatically re-loaded from TH when it
overflows. Thus, there is no software overhead for re-
loading the registers. This is convenient for generating
baud rates etc. The timing resolution is much lower in
this mode (only 8 bits). Therefore crystal frequencies
have to be carefully chosen to generate accurate baud
rates. Crystals of 11.059 MHz are often used rather than
12 MHz for this reason.
Mode 2

 Structure of Timer1 in mode 2:


Mode 3
 Split-timer mode
 Timer1 can be put in other modes

In this mode Timers T0 and T1 behave quite differently.


T0 acts as two independent 8 bit counters. Count register
TL0 uses the resources (such as the RUN flag, overflow flag)
in TCON, TMOD etc. meant for T0. Similarly, TH0 uses the
resources meant for T1. Thus, TR1 will enable running the 8
bit counter made up of TH0. TF1 will be set whenever TH0
overflows.
• T1 now has no control bits at all! It can only be
used for services which require no control, no
gating and no interrupts. Thus, T1 can be used
for Baud rate generation, while we still have two
timers available (both with 8 bit resolution).

3/15/2023 Baiju G S 50
Mode 3
 Structure of Timer 0 in mode 3:
Timer Modes
Example

 Choose mode 1 for Timer:


 MOV TMOD,#01H

Set the value of TH0 and TL0:
 MOV TH0,#FFH
 MOV TL0,#FCH

Clear Timer flag and start the timer:
 CLR TF0
 SETB TR0
Timer delay program for 8051
• Designing a delay program using 8051 timers.
• Assume the processor is clocked by a 12MHz crystal.
• A single machine cycle consists of 12 crystal pulses,
thus timer will count
• That means, the timer clock input will be 12MHz/12 =
1MHz.
• That means, the time taken for the timer to make one
increment = 1/1MHz = 1uS.
• For a time delay of “X” uS the timer has to make “X”
increments.
3/15/2023 Baiju G S 53
Example.
• Let the required delay be 1000uS (ie; 1mS).
• That means X = 1000
• 65536 – X = 65536 – 1000 = 64536.
• 64536 is considered in decimal and converting
it t0 hexadecimal gives FC18
• That means THTL = FC18
• Therefore TH=FC and TL=18

3/15/2023 Baiju G S 54
• Program for generating 1mS delay using 8051
timer.

• The program shown below can be used for


generating 1mS delay and it is written as a
subroutine so that you can call it anywhere in
the program. Also you can put this in a loop for
creating longer time delays (multiples of 1mS).
Here Timer 0 of 8051 is used and it is operating
in MODE1 (16 bit timer).

3/15/2023 Baiju G S 55
• DELAY: MOV TMOD,#00000001B // Sets Timer
0 to MODE1 (16 bit timer). Timer 1 is not used
• MOV TH0,#0FCH // Loads TH0 register with FCH
• MOV TL0,#018H // LOads TL0 register with 18H
• SETB TR0 // Starts the Timer 0
• HERE: JNB TF0,HERE // Loops here until TF0 is
set (ie; until roll over)
• CLR TR0 // Stops Timer 0
• CLR TF0 // Clears TF0 flag
• RET

3/15/2023 Baiju G S 56
The above delay routine can be looped twice in order to get a 2mS
delay and it is shown in the program below.

• MAIN: MOV R6,#2D


• LOOP: ACALL DELAY
• DJNZ R6,LOOP
• SJMP MAIN

• DELAY: MOV TMOD,#00000001B


• MOV TH0,#0FCH
• MOV TL0,#018H
• SETB TR0
• HERE: JNB TF0,HERE
• CLR TR0
• CLR TF0 3/15/2023 Baiju G S 57
SERIAL COMMUNICATION in 8051
Serial Communications
• Serial Communication (Telephone line)
• P/S: Parallel-in-Serial-out Shift Register
• S/P: Serial-in-Parallel-out Shift Register
• D/A: Digital-Analog Converter
• A/D: Analog-Digital Converter

Sender Receiver

City A P/S D/A


D/A A/D S/P
D/A City B

Baiju G S

3/15/2023 59
Serial vs Parallel communication

Baiju G S 60

3/15/2023
Serial v/s Parallel Communication

Parallel Communication Serial Communication


Often 8 or more lines (wire conductors) The data is sent one bit at a time on a
are used to transfer data. Multiple bits single line (wire)
are transferred at a time.
Preferred for short-distance Preferred over long-distance
communication communication
Costly as more resources are required Comparatively cheaper
Speed of data transfer is high Slow
Example: SPI, I2C, UART Example: PCI

3/15/2023 Baiju G S 61
Basics of Serial Communication
• Serial communication uses single data line making it much cheaper
• Enables two computers in different cities to communicate over the
telephone
• Byte of data must be converted to serial bits using a parallel-in-serial-
out shift register and transmitted over a single data line
• At the receiving end there must be a serial-in-parallel-out shift
register
• If transferred on the telephone line, it must be converted to audio
tones by modem for short distance

3/15/2023 Baiju G S 62
Modes of Serial Communication

Baiju G S 63

3/15/2023
Modes of Serial Communication
• In simplex transmissions, the computer can only send or receive
data. There is only one wire.
• If the data can be transmitted and received, then it is a duplex
transmission
• Duplex transmissions can be half or full duplex depending on
whether or not the data transfer can be simultaneous
• If the communication is only one way at a time, it is half duplex
• If both sides can communicate at the same time, it is full duplex
 Full duplex requires two wire conductors for the data lines
(in addition to the signal ground)

3/15/2023 Baiju G S 64
Basics of Serial Communication
• Serial Communication can be
 Asynchronous
 Synchronous
Synchronous Communication
• Synchronous methods transfer a block of data (characters) at a time
• The events are referenced to a clock
• Example: SPI bus, I2C bus
Asynchronous Communication
• Asynchronous methods transfer a single byte at a time
• There is no clock. The bytes are separated by start and stop bits.
• Example: UART

3/15/2023 Baiju G S 65
Basics of Serial Communication cont..
• To support serial communication, special interfaces are built in the
microcontroller.
• The microcontrollers use special IC chips called UART (universal
asynchronous receiver-transmitter) and USART (universal
synchronous asynchronous receiver-transmitter)
• 8051 chip has a built-in UART

3/15/2023 Baiju G S 66
TxD and RxD in 8051
• 8051 has two pins that are used specifically for transferring and
receiving data serially
 These two pins are called TxD and RxD and are part of the
port 3 group (P3.0 and P3.1)
 These pins are TTL compatible; therefore, they require a line
driver to make them RS232 compatible
• We need a line driver (voltage converter) to convert the R232’s
signals to TTL voltage levels that will be acceptable to 8051’s TxD
and RxD pins

3/15/2023 Baiju G S 67
Baud rate
• The baud rate is the rate at which
information is transferred in a
communication channel. Baud rate is
commonly used when discussing
electronics that use serial
communication. In the serial port context,
"9600 baud" means that the serial port is
capable of transferring a maximum of
9600 bits per second
3/15/2023 Baiju G S 68
Setting Baud rate in 8051
• Baud rate in the 8051 is programmable
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

3/15/2023 Baiju G S 69
Setting Baud rate in 8051
• Timer 1 must be programmed in mode 2, that is 8-bit, auto-reload

3/15/2023 Baiju G S 70
Setting Baud rate in 8051
• Timer 1 must be programmed in mode 2, that is 8-bit, auto-reload

3/15/2023 Baiju G S 71
SBUF Register

• SBUF Register: For a byte of data to be transferred via


the TxD line, it must be placed in the SBUF.
• SBUF holds the byte of data when it is received by
the 8051’s RxD line.
8051

Framed MAX232 DB-9 (RS232 Connector)

11 (P3.1) 11 T1 in T1 out 14 2 RxD


TxD
SBUF
RxD 10 (P3.0) 12 R1 out R1 in 13 3 TxD

Deframed 5
GND

Baiju G S

3/15/2023 72
SBUF Register cont..
• A byte of data to be transferred via the TxD line must be placed in the
SBUF register
• SBUF holds the byte of data when it is received by the RxD line
• SBUF can be accessed like any other register

 MOV SBUF, #'D' ;load SBUF=44H, ASCII for 'D‘

 MOV SBUF, A ;copy accumulator into SBUF


;
 MOV A, SBUF copy SBUF into accumulator

 When a byte is written in SBUF, it is framed by 8051 with the start and stop
bits and transferred serially via the TxD pin

3/15/2023 Baiju G S 73
SBUF Register cont..
 When the bits are received serially via RxD, it is deframed by 8051 by
eliminating the stop and start bits, making a byte out of the data
received, and then placing it in the SBUF
 Framing need not be done by programmer explicitly
• The special function register SBUF is physically two registers.
 One is, write-only and is used to hold data to be transmitted out of
the 8051 via TXD.
 The other is, read-only and holds the received data from external
sources via RXD.
• Both mutually exclusive registers have the same address 099H.
• SBUF is not bit addressable

3/15/2023 Baiju G S 74
SCON : Serial Control Register
Bit Addressable Register

SM0 SM1 SM2 REN TB8 RB8 TI RI

3/15/2023 Baiju G S 75
SM0 , SM1
 These two bits of SCON register determine the framing of
data by specifying the number of bits per character and
start bit and stop bits. There are 4 serial modes.

3/15/2023 Baiju G S 76
SM2
• n mode-2 and mode-3 the SM2 bit is used to
enable multiprocessor communication. In
multiprocessor communication the serial port
of a number of microcontrollers can be
connected to a common serial bus. One
controller will act as a master and all other
controller will act as slave.

3/15/2023 Baiju G S 77
REN
• REN (Receive Enable) also referred as SCON.4.
When it is high,it allows the 8051 to receive
data on the RxD pin. So to receive and transfer
data REN must be set to 1. When REN=0,the
receiver is disabled. This is achieved as below
SETB SCON.4
& CLR SCON.4

3/15/2023 Baiju G S 78
TI and RI Flags
TI (transmit interrupt)
• When 8051 finishes the transfer of the 8-bit character, it raises the
TI flag to indicate that it is ready to transfer another byte
• TI bit is raised at the beginning of the stop bit

RI (receive interrupt)
• When the 8051 receives data serially via RxD, it places the byte in
the SBUF register then raises the RI flag bit to indicate that a byte
has been received and should be picked up before it is lost
• RI is raised halfway through the stop bit

3/15/2023 Baiju G S 79
TB8 and RB8
• TB8 – The 9th bit that will be transmitted
in mode 2 and mode 3 , for an
information . set/clear by software.

• RB8 – In mode 2 and mode 3 it is the 9th


bit that was received. In mode 1 if SM2
=0, RB8 is the stop bit that was received.
In mode 0 RB8 it is not used.

3/15/2023 Baiju G S 80
Serial Data Transmission Modes
Mode 0
• In this mode, the serial port works like a shift register and the
data transmission works synchronously with a clock frequency of
fosc /12.
• Serial data is received and transmitted through RXD.
• 8 bits are transmitted/ received at a time.
• Pin TXD outputs the shift clock pulses of frequency fosc /12, which
is connected to the external circuitry for synchronization.
• The shift frequency or baud rate is always 1/12 of the oscillator
frequency.

3/15/2023 Baiju G S 81
Serial Data Transmission Modes
Mode 1
• In mode-1, the serial port functions as a standard Universal
Asynchronous Receiver Transmitter (UART) mode.
• 10 bits are transmitted through TXD or received through RXD.
• The 10 bits consist of one start bit (which is usually '0'), 8 data
bits (LSB is sent first/received first), and a stop bit (which is
usually '1').
• Once received, the stop bit goes into RB8 in the special function
register SCON. The baud rate is variable.

3/15/2023 Baiju G S 82
Serial Data Transmission Modes
Mode 2
• In this mode 11 bits are transmitted through TXD or received through
RXD.
• The various bits are as follows: a start bit (usually '0'), 8 data bits (LSB
first), a programmable 9 th (TB8 or RB8)bit and a stop bit (usually '1').
• While transmitting, the 9 th data bit (TB8 in SCON) can be assigned the
value '0' or '1'.
For example, if the information of parity is to be transmitted, the
parity bit (P) in PSW could be moved into TB8. On reception of the data,
the 9th bit goes into RB8 in 'SCON', while the stop bit is ignored.

The baud rate is programmable to either 1/32 or 1/64 of the oscillator


frequency.
• f baud = (2 SMOD /64) fosc.

3/15/2023 Baiju G S 83
Serial Data Transmission Modes
Mode 3
• In this mode 11 bits are transmitted through TXD or received
through RXD.
• The various bits are: a start bit (usually '0'), 8 data bits (LSB first),
a programmable 9 th bit and a stop bit (usually '1').
• Mode-3 is same as mode-2, except the fact that the baud rate in
mode-3 is variable (i.e., just as in mode-1).
• f baud = (2 SMOD /32) * ( fosc / 12 (256-TH1)) .
.

3/15/2023 Baiju G S 84
PCON register and Power Saving Modes in 8051

Baiju G S 85

3/15/2023
PCON register and Power Saving Modes in 8051

• Generally speaking, the microcontroller is inactive for the most part


and just waits for some external signal in order to takes its role in a
show.
• This can cause some problems in case batteries are used for power
supply.
• In extreme cases, the only solution is to set the whole electronics in
sleep mode in order to minimize consumption.

3/15/2023 Baiju G S 86
PCON register and Power Saving Modes in 8051

Idle Mode
• Upon the IDL bit of the PCON register is set, the microcontroller turns
off the CPU unit while peripheral units such as serial port, timers and
interrupt system continue operating normally
• In Idle mode, the state of all registers and I/O ports remains
unchanged.
• In order to exit the Idle mode and make the microcontroller
operate normally, it is necessary to reset.
• It will cause the IDL bit to be automatically cleared and the program
resumes operation from instruction having set the IDL bit.

3/15/2023 Baiju G S 87
PCON register and Power Saving Modes in 8051

Power Down Mode


• By setting the PD bit of the PCON register from within the
program, the microcontroller is set to Power down mode,
• In power down mode, internal oscillator is off and reduces power
consumption enormously.
• The only way to get the microcontroller back to normal mode is by
reset.
• While the microcontroller is in Power Down mode, the state of all
SFR registers and I/O ports remains unchanged.
• By setting it back into the normal mode, the contents of the SFR
register is lost, but the content of internal RAM is saved.

3/15/2023 Baiju G S 88
Doubling the Baud Rate in 8051
• There are two ways to increase the baud rate of data transfer
 To use a higher frequency crystal
 To set the SMOD bit in the PCON register
• PCON register is an 8-bit register, whose MSB is SMOD
• When 8051 is powered up, SMOD is zero
• We can set it to high by software and thereby double the baud rate
• PCON is not bit-addressable register. Hence, we cannot set SMOD bit directly. This
may be done as:
MOV A, PCON ;place a copy of PCON in ACC
SETB ACC.7 ;make D7=1
MOV PCON,A ;changing any other bits

3/15/2023 Baiju G S 89
Doubling the Baud Rate in 8051

Baiju G S 90

3/15/2023
Thank you

Baiju G S 91

3/15/2023

You might also like