100% found this document useful (1 vote)
359 views

Unit4_EE3404_MPMC

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
100% found this document useful (1 vote)
359 views

Unit4_EE3404_MPMC

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/ 189

EE3404 (MP&MC)

[Regulation-2021]

Microprocessor & Microcontroller


(Second Year, 4th Semester EEE)

Unit 4
Introduction to 8051
Microcontroller
MP&MC/EE3404 Lecture Notes
by
Dr.I.William Christopher
Asso.Prof/EEE Dept./LICET
6/9/2024 EE3404/MPMC/Unit-4 1
Course Objectives
▪ To study the addressing modes & instruction set of 8085
& 8051

▪ To develop skills in simple program writing in assembly


languages

▪ To introduce commonly used peripheral/interfacing ICs.

▪ To study and understand typical applications of micro-


processors.

▪ To study and understand the typical applications of


micro-controllers
6/9/2024 EE3404/MPMC/Unit-4 2
Course Outcomes
Upon successful completion of the course, the students should have
the:
C01 Ability to write assembly language program for microprocessor
and microcontroller
C02 Ability to design and implement interfacing of peripheral with
microprocessor and microcontroller
C03 Ability to analyze, comprehend, design and simulate
microprocessor based systems used for control and monitoring.
C04 Ability to analyze, comprehend, design and simulate
microcontroller based systems used for control and monitoring.
C05 Ability to understand and appreciate advanced architecture
evolving microprocessor field

6/9/2024 EE3404/MPMC/Unit-4 3
Units of Microprocessor & Microcontroller
The Course deals with the following Units:
Unit –I : Introduction to 8085 Architecture

Unit –II : 8085 Instruction Set and Programming

Unit –III : Interfacing Basics and ICs

Unit –IV : Introduction to 8051 Microcontroller

Unit –V : Introduction to RISC Based Architecture

6/9/2024 EE3404/MPMC/Unit-4 4
Text and Reference Books
Textbooks:
1) Ramesh S. Gaonkar, ‘Microprocessor Architecture Programming and
Application’, Pen ram International (P)ltd., Mumbai, 6th Education, 2013.
2) Muhammad Ali Mazidi & Janice Gilli Mazidi, ‘The 8051 Micro Controller
and Embedded Systems’, Pearson Education, Second Edition 2011.
3) Muhammad Ali Mazidi & Janice Gilli Mazidi, ‘The PIC Micro Controller
and Embedded Systems’, 2010
Reference Books:
1) Douglas V. Hall, “Micro-processors & Interfacing”, Tata McGraw Hill 3rd
Edition, 2017.
2) Krishna Kant, “Micro-processors & Micro-controllers”, Prentice Hall of
India, 2007.
3) Mike Predko, “8051 Micro-controllers”, McGraw Hill, 2009
4) Kenneth Ayala, ‘The 8051 Microcontroller’, Thomson, 3rd Edition 2004.
6/9/2024 EE3404/MPMC/Unit-4 5
Unit-I: Introduction to 8085 Architecture

Topics to be discussed:
▪ Functional Block Diagram

▪ Memory Interfacing

▪ I/O Ports and Data Transfer Concepts

▪ Timing Diagram

▪ Interrupt Structure

6/9/2024 EE3404/MPMC/Unit-4 6
Unit-II: 8085 Instruction Set and Programming
Topics to be discussed:
▪ Instruction Format and Addressing Modes
▪ Assembly Language Format
▪ Data Transfer, Data Manipulation &
Control Instructions
▪ Programming:
✓Loop structure with Counting & Indexing
✓Look up table
✓Subroutine instructions
✓Stack
6/9/2024 EE3404/MPMC/Unit-4 7
Unit-III: Interfacing Basics and ICs
Topics to be discussed:
▪ Study of Architecture and programming of ICs:
✓ 8255 - PPI
✓ 8259 - PIC
✓ 8251 - USART
✓ 8279 - Keyboard display controller
✓ 8254 - Timer/Counter
▪ Interfacing with 8085
✓A/D and D/A converter interfacing
6/9/2024 EE3404/MPMC/Unit-4 8
Unit-IV: Introduction to 8051 Microcontroller
Topics to be discussed:
▪ Functional Block Diagram
▪ Instruction Format And Addressing Modes
▪ Interrupt Structure
▪ Timer
▪ I/O Ports
▪ Serial Communication
▪ Simple Programming
▪ Keyboard And Display Interface
▪ Temperature Control System
▪ Stepper Motor Control
▪ Usage of IDE for Assembly Language Programming
6/9/2024 EE3404/MPMC/Unit-4 9
Unit-V: Introduction to RISC Based Architecture
Topics to be discussed:
▪ PIC16 /18 Architecture
▪ Memory Organization
▪ Addressing Modes
▪ Instruction Set
▪ Programming Techniques
▪ Timers
▪ I/O Ports
▪ Interrupt Programming
6/9/2024 EE3404/MPMC/Unit-4 10
Introduction

➢ Microprocessor – silicon chip which includes ALU,


register circuits & control circuits.

➢ Microcontroller – silicon chip which includes


microprocessor, memory & I/O in a single package.

➢ Microcomputer – a computer with a microprocessor


as its CPU. Includes memory, I/O etc.

6/9/2024 EE3404/MPMC/Unit-4 11
Introduction to Microcontrollers
• Microcontroller – silicon chip which includes microprocessor,
memory & I/O ports in a single package.
• A Microcontroller has a CPU (Microprocessor) in addition to a
fixed amount of RAM,ROM, I/O ports and a timer all on a single
chip.
• 8051/8031 is a 8- bit Microcontroller.
• It has, ✓ CPU + I/O + Timer's) [+ ROM] [+ RAM]
✓ Low to moderate performance only
✓ Limited RAM space, ROM space and I/O pins
✓ EPROM version available
✓ Low chip-count to implement a small system
✓ Low-cost at large quantities
✓ Development tools readily available at reasonable
6/9/2024 EE3404/MPMC/Unit-4 12
Features of 8051/8031 Microcontroller
• ROM – 4K bytes
• RAM – 128 bytes
• Timers – ‘2’ (Timer 0, Timer 1)
• I/O Pins – ‘32’ [4 ports: Port 0 (AD0-AD7); Port 1;
Port 2 (A8-A15); Port 3 (Important Alternate Functions);
Each Port has 8 I/O pins]
• Serial Port – ‘1’ (UART : TxD (Transmit Data);
RxD (Receive Data);)
• Interrupt Sources – ‘6’ ( IE0; IE1; TF0; TF1; RI+TI )
• 8031 is called “ROM-less 8051”
• 8052 has all features of 8051 in addition to an extra 128 bytes of
RAM, extra Timer and extra 2 Interrupt Sources.
6/9/2024 EE3404/MPMC/Unit-4 13
Pin out of 8051 Microcontroller

6/9/2024 EE3404/MPMC/Unit-4 14
Pin out of
8051
Microcontroller

6/9/2024 EE3404/MPMC/Unit-4 15
Pin Descriptions of 8051

6/9/2024 EE3404/MPMC/Unit-4 16
Alternate functions of Port pins of 8051

6/9/2024 EE3404/MPMC/Unit-4 17
Functional block diagram/Architecture of 8051/8031

6/9/2024 EE3404/MPMC/Unit-4 18
Architecture of 8051 Microcontroller

6/9/2024 EE3404/MPMC/Unit-4 19
8-bit Registers of 8051

6/9/2024 EE3404/MPMC/Unit-4 20
Register Banks of 8051 Microcontroller
▪ Four banks of 8 byte-sized registers, Each Bank has 8
Registers R0 to R7
▪ Addresses are :
18H - 1FH for bank 3
10H – 17H for bank 2
08H - 0FH for bank 1
00H - 07H for bank 0 (default)
▪ Active bank selected by bits [ RS1, RS0 ] in PSW (Program Status
Word).
▪ Permits fast “context switching” in Interrupt Service Routines (ISR).
6/9/2024 EE3404/MPMC/Unit-4 21
Program Status Word (PSW) of 8051

6/9/2024 EE3404/MPMC/Unit-4 22
Register Bank of 8051

6/9/2024 EE3404/MPMC/Unit-4 23
16-bit Registers of 8051

Stack Pointer (8-bit)


D7 D0

Program Counter (16-bit)


D15 D0

DPTR (Data Pointer: 16-bit)

DPH DPL
D15 D8 D7 D0

6/9/2024 EE3404/MPMC/Unit-4 24
16-bit CPU Registers of 8051
Stack Pointer :
✓ It is 8 bit wide.
✓ It is incremented before data is stored during PUSH and CALL
instructions.
✓ The stack array can reside anywhere in on-chip RAM.
✓ The stack pointer is initialized to 07H after a reset.
✓ This causes the stack to begin at location 08H.
Data Pointer (DPTR) :
✓ It consists of a high byte (DPH) and a low byte (DPL).
✓ Its function is to hold a 16 bit address.
✓ It may be manipulated as a 16 bit data register or as two
independent 8 bit registers.
✓ It serves as a base register in indirect jumps, lookup table
instructions and external data transfer.

6/9/2024 EE3404/MPMC/Unit-4 25
Von Neumann & Harvard Architectures

6/9/2024 EE3404/MPMC/Unit-4 26
Memory Space of 8051

6/9/2024 EE3404/MPMC/Unit-4 27
PolyU 11
Memory Organization of 8051

6/9/2024 EE3404/MPMC/Unit-4 28
Program Memory
✓ When the EA pin is connected to Vcc, program fetches to addresses 0000H
through OFFFH are directed to the internal ROM and program fetches to
addresses 1000H through FFFFH are directed to external ROM/EPROM.

✓ On the other hand when EA pin is grounded, all addresses (0000H to FFFFH)
fetched by program are directed to the external ROM/EPROM.

6/9/2024 EE3404/MPMC/Unit-4 29
Accessing External
Accessing External Code Memory
The PSEN signal is used to Code
activate Memory
output enable signal of the
external ROM/EPROM , as shown in the Figure.

Figure 2-8
Accessing
external
code
memory

Dr. Jimmy To, EIE, PolyU 18


6/9/2024 EE3404/MPMC/Unit-4 30
Timing diagram for
External Program Memory Read Cycle

6/9/2024 EE3404/MPMC/Unit-4 31
8051 Data Memory
✓ The 8051 can address up to 64 Kbytes of external data
memory.

✓ The “MOVX” instruction is used to access the external


data memory.

✓ The internal data memory space for Intel 8051


Architecture and 8031 Architecture is divided into three
blocks :
1. Lower 128 bytes,
2. Upper 128 bytes and
3. Special Function Registers (SFRs).
6/9/2024 EE3404/MPMC/Unit-4 32
8051 Data Memory

6/9/2024 EE3404/MPMC/Unit-4 33
Data Memory
Accessing External Data Memory

Figure
2-11
nterface
to 1K
RAM

Jimmy To, EIE, PolyU 20


6/9/2024 EE3404/MPMC/Unit-4 34
Timing diagram for
External Data Memory Read Cycle

6/9/2024 EE3404/MPMC/Unit-4 35
Timing diagram for
External Data Memory Write Cycle

6/9/2024 EE3404/MPMC/Unit-4 36
Special Function Registers (SFRs)
✓ Unlike other microprocessors in the Intel family, 8051 uses
memory mapped I/O through a set of special function
registers that are implemented in the address space
immediately above the 128 bytes of RAM.

✓ All access to the


1. Four I/O ports,
2. CPU registers,
3. Interrupt-control registers,
4. Timer/counter,
5. UART, and
6. Power control registers
are performed through registers between 80H and FFH.
6/9/2024 EE3404/MPMC/Unit-4 37
Special Function Registers (SFRs)

6/9/2024 EE3404/MPMC/Unit-4 38
Special Function Registers (SFRs)

6/9/2024 EE3404/MPMC/Unit-4 39
I/O Ports of 8051
✓ I/O Ports The 8051 has 4 bidirectional 8-bit I/O ports.
✓ Each port is connected to an 8-bit register in the SFR.
✓ P0 = 80H, P1 = 90H, P2 = A0H, P3 = B0H
✓ Each port is also connected to an output driver and an
input buffer.
✓ All ports are configured for output at reset.
✓ Some of the 4 ports have uses in addition to simple I/O.
✓ Ports P0 and P2 double as the 8051’s Address and Data
busses.
✓ Port P3 doubles as the 8051’s external control lines for the
timers and counters.

6/9/2024 EE3404/MPMC/Unit-4 40
I/O Ports of 8051
Port P0 :
✓P0 can be used for input or output.
✓The pins of P0 are connected internally to an “open drain”
circuit (similar to open collector but using MOS
transistors).
✓Therefore, it must be connected to an external pull-up
resistor (10 KΩ ) to operate properly as an output port.
✓To operate P0 as an input port, it must be programmed by
writing 1’s to all of its bits

6/9/2024 EE3404/MPMC/Unit-4 41
I/O Ports of 8051
Pull-up Resistor Pull-down Resistor

6/9/2024 EE3404/MPMC/Unit-4 42
I/O Ports of 8051
Port P0

6/9/2024 EE3404/MPMC/Unit-4 43
I/O Ports of 8051
Port P0

6/9/2024 EE3404/MPMC/Unit-4 44
I/O Ports of 8051
Dual Role of P0 :

✓ P0 is also designated as AD0 – AD7 which means that it


also doubles as the multiplexed lower 8 bits of the
address bus and the 8 bits of the data bus.
✓ P0 will be used in this manner when accessing external
memory.
✓ Program or data. – ALE is used to differentiate when the
pins are carrying an address vs. data. ALE = 1 when the
pins carry an address and 0 otherwise.
✓ ALE can be used to enable an external address latch that
will hold the address value after it has been removed
from the pins.
6/9/2024 EE3404/MPMC/Unit-4 45
I/O Ports of 8051
Port P1 :
✓ Port 1 occupies a total of 8 pins (pins 1 through 8).
✓ It can be used as input or output.
✓ In contrast to port 0, this port does not need any
pull-up resistors since it already has pull-up resistors
internally.
✓ Upon reset, Port 1 is configured as an output port.
✓ For example, the following code will continuously
send out to port1 the alternating values 55h & AAh.
6/9/2024 EE3404/MPMC/Unit-4 46
I/O Ports of 8051
Port P1 :

6/9/2024 EE3404/MPMC/Unit-4 47
I/O Ports of 8051
Port P1 as Input:

✓ To make port P1 an input port, it must programmed


as such by writing 1 to all its bits.
✓ Port P1 is configured first as an input port by writing
1’s to it, then data is received from the port and
saved in R7 ,R6 & R5.

6/9/2024 EE3404/MPMC/Unit-4 48
I/O Ports of 8051
Port P2 :

✓ Port 2 occupies a total of 8 pins (pins 21- 28).


✓ It can be used as input or output.
✓ Just like P1, P2 does not need any pull-up resistors
since it already has pull-up resistors internally.
✓ Upon reset, Port 2 is configured as an output port.
✓ To make port 2 an input, it must programmed as such
by writing 1 to all its bits..

6/9/2024 EE3404/MPMC/Unit-4 49
I/O Ports of 8051
Port P2 :

6/9/2024 EE3404/MPMC/Unit-4 50
I/O Ports of 8051
Dual role of Port P2 :
✓ It is also designed as A8-A15, indicating the dual function.
✓ Since an 8051 is capable of accessing 64K bytes of
external memory, it needs a path for the 16 bits of the
address.
✓ While P0 provides the lower 8 bits via A0-A7, it is the job
of P2 to provide bits A8-A15 of the address.
✓ In other words, when 8051 is connected to external
memory, P2 is used for the upper 8 bits of the 16 bit
address, and it cannot be used for I/O.

6/9/2024 EE3404/MPMC/Unit-4 51
I/O Ports of 8051
Port P3 :
✓ Port 3 occupies a total of 8 pins, pins 10 through 17.
✓ It can be used as input or output.
✓ P3 does not need any pull-up resistors, the same as
P1 and P2 did not.
✓ Although port 3 is configured as an output port upon
reset.
✓ Port 3 has the additional function of providing some
extremely important signals such as interrupts.

6/9/2024 EE3404/MPMC/Unit-4 52
I/O Ports of 8051
Port P3 :

6/9/2024 EE3404/MPMC/Unit-4 53
I/O Ports of 8051
Dual Role of Port P3 :
✓ Port 3 occupies a total of 8 pins, pins 10 through 17.
✓ It can be used as input or output.
✓ P3 does not need any pull-up resistors, the same as P1
and P2 did not.
✓ Although port 3 is configured as an output port upon
reset.
✓ P3.0 and P3.1 are used for the RxD and TxD serial
communications signals.
✓ Bits P3.2 and P3.3 are set aside for external interrupts.
✓ Bits P3.4 and P3.5 are used for timers 0 and 1.
✓ Finally P3.6 and P3.7 are used to provide the WR and RD
signals
6/9/2024 EE3404/MPMC/Unit-4 54
I/O Ports of 8051
Alternate functions of Port P3 :

6/9/2024 EE3404/MPMC/Unit-4 55
Timers of 8051
✓ 8051 has two 16-bit programmable UP timers/counters.

✓ They can be configured to operate either as timers or as


event counters.

✓ The names of the two timers are T0 and T1 respectively.

✓ The timer content is available in four 8-bit special


function registers, viz, TL0,TH0,TL1 and TH1 respectively.

6/9/2024 EE3404/MPMC/Unit-4 56
Timers of 8051

6/9/2024 EE3404/MPMC/Unit-4 57
Timers of 8051
Clock
✓ Every Timer needs a clock to work, and 8051 provides it
from an external crystal which is the main clock source for
Timer.
✓ The internal circuitry in the 8051 microcontrollers
provides a clock source to the timers which is 1/12th of
the frequency of crystal attached to the microcontroller,
also called as Machine cycle frequency.

6/9/2024 EE3404/MPMC/Unit-4 58
Timers of 8051
Clock
For example, suppose we have crystal frequency of
11.0592 MHz then microcontroller will provide 1/12th
i.e.
Timer clock frequency
= (Crystal Oscillator frequency)/12
= (11.0592 MHz)/12
= 921.6 KHz
period T = 1/(921.6 KHz)=1.085 μS

6/9/2024 EE3404/MPMC/Unit-4 59
Timers of 8051
✓ In the “Timer" function mode, the counter is incremented in
every machine cycle. Thus, one can think of it as counting
machine cycles. Hence the clock rate is 1/12 th of the
oscillator frequency.
✓ In the "Counter" function mode, the register is incremented
in response to a 1 to 0 transition at its corresponding
external input pin (T0 or T1).
✓ It requires 2 machine cycles to detect a high to low
transition. Hence maximum count rate is 1/24 th of oscillator
frequency.
✓ The operation of the timers/counters is controlled by two
special function registers, TMOD and TCON respectively.
6/9/2024 EE3404/MPMC/Unit-4 60
Timers of 8051
TMOD (Timer Mode) Register

6/9/2024 EE3404/MPMC/Unit-4 61
Timers of 8051
TCON (Timer Control) Register (1)

6/9/2024 EE3404/MPMC/Unit-4 62
Timers of 8051
TCON (Timer Control) Register (2)

6/9/2024 EE3404/MPMC/Unit-4 63
TMOD (Timer Mode) Register of 8051
Mode-0 (13-bit timer mode)
✓ Mode 0 is 13-bit timer mode for which 8-bit of THx and 5-bit of TLx
(as Pre-scaler) are used.
✓ It is mostly used for interfacing possible with old MCS-48 family
microcontrollers.

Higher 3-bits of TLx should be written as zero while using timer


mode0, or it will affect the result.
6/9/2024 EE3404/MPMC/Unit-4 64
TMOD (Timer Mode) Register of 8051
Mode-0 (13-bit timer mode)

✓ The input pulse is obtained from the previous stage.


✓ If TR1/0 bit is 1 and Gate bit is 0, the counter continues counting
up.
✓ If TR1/0 bit is 1 and Gate bit is 1, then the operation of the
counter is controlled by input.
✓ This mode is useful to measure the width of a given pulse fed
to input.
6/9/2024 EE3404/MPMC/Unit-4 65
TMOD (Timer Mode) Register of 8051
Mode-1 (16-bit timer mode)
Mode 1 is 16-bit timer mode used to generate a delay, it uses 8-bit of
THx and 8-bit of TLx to form a total 16-bit register.

6/9/2024 EE3404/MPMC/Unit-4 66
TMOD (Timer Mode) Register of 8051
Mode-1 (16-bit timer mode)

This mode is similar to mode-0 except for the fact that the Timer
operates in 16-bit mode.

6/9/2024 EE3404/MPMC/Unit-4 67
TMOD (Timer Mode) Register of 8051
Mode-2 (8-bit auto-reload timer mode)
✓ Mode 2 is 8-bit auto-reload timer mode.
✓ In this mode we have to load the THx-8 bit value only.
✓ when the Timer gets started, THx value gets automatically loaded
into the TLx and TLx start counting from that value.
✓ After the value of TLx overflows from the 0xFF to 0x0, the TFx flag
gets set and again value from the THx gets automatically loaded
into the TLx register. That’s why this is called as auto reload mode.

6/9/2024 EE3404/MPMC/Unit-4 68
TMOD (Timer Mode) Register of 8051
Mode-2 (8-bit auto-reload timer mode)
✓ This is a 8 bit counter/timer operation.
✓ Counting is performed in TLX while THX stores a constant value.
✓ In this mode when the timer overflows i.e. TLX becomes FFH, it is
fed with the value stored in THX.
✓ For example if we load THX with 50H then the timer in mode 2
will count from 50H to FFH. After that 50H is again reloaded. This
mode is useful in applications like fixed time sampling.

6/9/2024 EE3404/MPMC/Unit-4 69
TMOD (Timer Mode) Register of 8051
Mode-3 (Split timer mode)
✓ Timer 1 in mode-3 simply holds its count.
✓ The effect is same as setting TR1=0. Timer0 in mode-3 establishes
TL0 and TH0 as two separate counters.
✓ Control bits TR1 and TF1 are used by Timer-0 (higher 8 bits) (TH0)
in Mode-3 while TR0 and TF0 are available to Timer-0 lower 8
bits(TL0).

6/9/2024 EE3404/MPMC/Unit-4 70
Timer interrupt in 8051
✓ It has two timer interrupts assigned with different vector address.
✓ When Timer count rolls over from its max value to 0, it sets timer
flag TFx. This will interrupt the 8051 microcontroller to serve ISR
(interrupt service routine) if global and timer interrupt is enabled.
✓ Timer overflow interrupt assigned with vector address shown in the
table.
✓ 8051 microcontroller jumps directly to the vector address on the
occurrence of a corresponding interrupt.
Interrupt source Vector address
Timer 0 overflow (TF0) 000BH
Timer 1 overflow (TF1) 001BH

6/9/2024 EE3404/MPMC/Unit-4 71
Interrupts of 8051
✓ Interrupts are basically the events that temporarily
suspend the main program, pass the control to the
external sources and execute their task.
✓ It then passes the control to the main program where it
had left off.
✓ 8051 has five interrupts.
✓ All of the interrupts can be enabled or disabled by using
the IE (Interrupt Enable) register.
✓ The Interrupts priority level can be decided by using the
IP (Interrupt Priority) register
6/9/2024 EE3404/MPMC/Unit-4 72
Interrupts of 8051
✓ Interrupts and their vector addresses are given below

Interrupt Address
INT0 0003H
INT1 000BH
T0 0013H
T1 001BH
TI/RI 0023H

6/9/2024 EE3404/MPMC/Unit-4 73
Interrupt Structure of 8051

6/9/2024 EE3404/MPMC/Unit-4 74
Interrupt Structure of 8051

6/9/2024 EE3404/MPMC/Unit-4 75
IE (Interrupt Enable) Register
✓ This register can be used to enable or disable interrupts
programmatically.
✓ This register is an SFR and the address is A8H.

6/9/2024 EE3404/MPMC/Unit-4 76
IP (Interrupt Priority) Register

6/9/2024 EE3404/MPMC/Unit-4 77
Basics of Serial Communication (1)
Serial versus Parallel Data Transfer-1

6/9/2024 EE3404/MPMC/Unit-4 78
Basics of Serial Communication (2)
Serial versus Parallel Data Transfer-2

6/9/2024 EE3404/MPMC/Unit-4 79
Basics of Serial Communication (3)
Simplex, Half-, and Full-Duplex Transfers

6/9/2024 EE3404/MPMC/Unit-4 80
Basics of Serial Communication (4)
Asynchronous Communication Synchronous Communication
Transmitter and receiver are not Transmitter and receiver are
synchronized by clock. synchronized by clock.
Character may arrive at any rate at Character is received at constant
receiver rate.
Data transfer is character oriented Data transfer takes place in blocks.
Start and stop bits are not required
Start and stop bits are required to to establish communication of each
establish communication of each character, however
character. ,synchronization bits are required
to transfer the data block.
Used in low-speed transmissions Used in high-speed transmission

6/9/2024 EE3404/MPMC/Unit-4 81
Basics of Serial Communication (5)
Asynchronous Data Framing – Start & Stop Bits

Framing ASCII “A” (41H)

6/9/2024 EE3404/MPMC/Unit-4 82
Basics of Serial Communication (6)
Data Transfer Rate
▪ The rate of data transfer in serial data communication is stated in
bps (bits per second).
▪ Another widely used terminology for bps is baud rate. However,
the baud and bps rates are not necessarily equal.
▪ This is because baud rate is the modem terminology and is defined
as the number of signal changes per second.
▪ In modems a single change of signal sometimes transfers several
bits of data.
▪ As far as the conductor wire is concerned, the baud rate and bps
are the same

6/9/2024 EE3404/MPMC/Unit-4 83
Basics of Serial Communication (7)
RS232 Standards (1)
▪ To allow compatibility among data communication equipment
made by various manufacturers, an interfacing standard called
RS232 was set by the Electronics Industries Association (EIA) in
1960.
▪ In 1963, it was modified and called RS232A.
▪ RS232B and RS232C were issued in 1965 and 1969, respectively.
▪ Here, we refer to it simply as RS232.
▪ Today, RS232 is the most widely used serial I/O interfacing
standard.
▪ This standard is used in PCs and numerous types of equipment.
6/9/2024 EE3404/MPMC/Unit-4 84
Basics of Serial Communication (8)
RS232 Standards (2)
▪ However, since the standard was set long before the advent of the
TTL logic family, its input and output voltage levels are not TTL-
compatible.

▪ In RS232, a 1 is represented by −3 to −25 V, while a 0 bit is +3 to


+25 V, making −3 to +3 undefined.

▪ For this reason, to connect any RS232 to a microcontroller system


we must use voltage converters such as MAX232 to convert the
TTL logic levels to the RS232 voltage levels, and vice versa.

▪ MAX232 IC chips are commonly referred to as line drivers.

6/9/2024 EE3404/MPMC/Unit-4 85
Basics of Serial Communication (9)
RS232 Pins – DB 25 Connector

6/9/2024 EE3404/MPMC/Unit-4 86
Basics of Serial Communication (10)
RS232 Pins – DB 9 Connector

6/9/2024 EE3404/MPMC/Unit-4 87
Basics of Serial Communication (12)
Null Modem Connection

6/9/2024 EE3404/MPMC/Unit-4 88
Serial Communication in 8051 (1)
✓ The RS232 standard is not TTL-compatible;
✓ Therefore, it requires a line driver such as the MAX232 chip to
convert RS232 voltage levels to TTL levels, and vice versa. T

6/9/2024 EE3404/MPMC/Unit-4 89
Serial Communication in 8051 (2)
Baud Rate:-The rate at which the number of bits are
transmitted

8051 Registers related to Serial Communication

1. SBUF Register -- to hold data

2. SCON Register -- controls data communication

3. PCON Register -- controls data rates

6/9/2024 EE3404/MPMC/Unit-4 90
Serial Communication in 8051 (3)
Serial Interface
✓ The serial port of 8051 is full duplex, i.e., it can transmit and
receive simultaneously.

✓ The register SBUF is used to hold the data. 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.

6/9/2024 EE3404/MPMC/Unit-4 91
Serial Communication in 8051 (4)
SBUF Register
• It is an 8-bit register used for serial communication.
• For a byte data to be transferred via the TxD line, it must be
placed in the SBUF register.
• The moment a byte is written into SBUF, it is framed with the start
and stop bits and transferred serially via the TxD line.
• SBUF holds the byte of data when it is received by 8051 RxD line.
• When the bits are received serially via RxD, the 8051 deframes it
by eliminating the stop and start bits, making a byte out of the
data received, and then placing it in SBUF.

6/9/2024 EE3404/MPMC/Unit-4 92
Serial Communication in 8051 (5)
Serial Port Control Register (SCON)-1
Register SCON controls serial data communication.
Address: 098H (Bit addressable)

6/9/2024 EE3404/MPMC/Unit-4 93
Serial Communication in 8051 (6)
Serial Port Control Register (SCON)-2
Register SCON controls serial data communication.
Address: 098H (Bit addressable)

6/9/2024 EE3404/MPMC/Unit-4 94
Serial Communication in 8051 (7)
PCON (Power Control Register)

6/9/2024 EE3404/MPMC/Unit-4 95
Addressing Modes of 8051 Microcontroller (1)
▪ The length of an 8051 instruction is 1, 2, or 3 bytes.
▪ The opcode for an instruction is always 8 bits long. Hence 28
256 opcodes are possible, of which 255 opcodes have been
implemented.
▪ They can be classified into 111 types of instructions.
▪ If the crystal frequency is 12 MHz, then 64 instruction types are
executed in just 1s, and the rest in just 2s (except for multiply
and divide instructions that need 4s).
▪ Intel 8051 provides the following addressing modes for
accessing data from internal data memory or external data
memory

6/9/2024 EE3404/MPMC/Unit-4 96
Addressing Modes of 8051 Microcontroller (2)
▪ The CPU can access data in various ways.
▪ The data could be in a register, or in memory, or be provided
as an immediate value.
▪ These various ways of accessing data are called addressing
modes.
▪ The 8051 provides distinct addressing modes. They are as
follows:
1) Register Addressing
2) Register Indirect Addressing
3) Direct Byte Addressing
4) Stack Addressing
5) Register-Specific/ Implied Addressing
6) Immediate Addressing
7) Base + Index Register Addressing
6/9/2024 EE3404/MPMC/Unit-4 97
Addressing Modes of 8051 Microcontroller (3)
Register Addressing
▪ It involves the use of registers to hold the data to be
manipulated.
▪ Examples

6/9/2024 EE3404/MPMC/Unit-4 98
Addressing Modes of 8051 Microcontroller (4)
Register Indirect Addressing (1)
▪ In this mode, a register is used as a pointer to the data.
▪ If the data is inside the CPU, only registers R0 and R1 are
used for this purpose
▪ When R0 and R1 are used as pointers, that is, when they
hold the addresses of RAM locations, they must be
preceded by the “@” sign
▪ Examples

6/9/2024 EE3404/MPMC/Unit-4 99
Addressing Modes of 8051 Microcontroller (5)
Register Indirect Addressing (2)
Examples:
MOV A, @R1

6/9/2024 EE3404/MPMC/Unit-4 100


Addressing Modes of 8051 Microcontroller (6)
Direct Byte Addressing (1)
▪ There are 128 bytes of RAM in the 8051.
▪ The RAM has been assigned addresses 00 to 7FH.
▪ The following is a summary of the allocation of these 128
bytes.
1) RAM locations 00–1FH are assigned to the register banks and
stack.
2) RAM locations 20–2FH are set aside as bit-addressable space
to save single-bit data.
3) RAM locations 30–7FH are available as a place to save byte-
sized data.

6/9/2024 EE3404/MPMC/Unit-4 101


Addressing Modes of 8051 Microcontroller (7)
Direct Byte Addressing (2)
▪ Although the entire 128 bytes of RAM can be accessed using
direct addressing mode, it is most often used to access RAM
locations 30–7FH.

▪ This is because register bank locations are accessed by the


register names of R0–R7, but there is no such name for other
RAM locations.

▪ In the direct addressing mode, the data is in a RAM location


whose address is known, and this address is given as a part of
the instruction.

6/9/2024 EE3404/MPMC/Unit-4 102


Addressing Modes of 8051 Microcontroller (8)
Direct Byte Addressing (3)
Examples :

6/9/2024 EE3404/MPMC/Unit-4 103


Addressing Modes of 8051 Microcontroller (9)
Direct Byte Addressing (4)
Examples :
MOV A, 33H
MOV 32, R1

6/9/2024 EE3404/MPMC/Unit-4 104


Addressing Modes of 8051 Microcontroller (10)
Stack and Direct Addressing
▪ Another major use of direct addressing mode is the stack.
▪ In the 8051 family, only direct addressing mode is allowed for
pushing onto the stack. (PUSH instruction)
▪ Direct addressing mode must be used for the POP instruction as
well
▪ Examples:

6/9/2024 EE3404/MPMC/Unit-4 105


Addressing Modes of 8051 Microcontroller (11)
Register Specific/Implied Addressing
▪ Inherent in the instruction, these refer to a specific
register such as an accumulator (A) or DPTR
▪ Examples:
SWAP A
RL A
RR A
CPL A

6/9/2024 EE3404/MPMC/Unit-4 106


Addressing Modes of 8051 Microcontroller (12)
Immediate Addressing
▪ In this addressing mode, the source operand is a constant.
▪ In immediate addressing mode, as the name implies, when the
instruction is assembled, the operand comes immediately after
the opcode.
▪ Notice that the immediate data must be preceded by the pound
sign, “#”.
▪ Examples

6/9/2024 EE3404/MPMC/Unit-4 107


Addressing Modes of 8051 Microcontroller (13)
Base + Index Register Addressing (1)
▪ Indexed addressing mode is widely used in accessing data elements
of look-up table entries located in the program ROM space of the
8051.
▪ The instruction used for this purpose is “MOVC A,@A+DPTR”. The
16-bit register DPTR and register A are used to form the address of
the data element stored in the on-chip ROM.
▪ Because the data elements are stored in the program (code) space
ROM of the 8051, the instruction MOVC is used instead of MOV.
▪ The “C” means code.
▪ In this instruction the contents of A are added to the 16-bit register
DPTR to form the 16-bit address of the needed data.
6/9/2024 EE3404/MPMC/Unit-4 108
Addressing Modes of 8051 Microcontroller (14)
Base + Index Register Addressing (2)
Examples:
▪ MOVC A,@A+PC : Move a byte of data from program memory,
whose address can be determined by the sum of the accumulator
and program counter, to the accumulator.

▪ MOVC A,@A+DPTR: Move a byte of data from program memory,


whose address can be found by adding the accumulator and the
data pointer, to the accumulator

6/9/2024 EE3404/MPMC/Unit-4 109


Addressing Modes of 8051 Microcontroller (15)
Base + Index Register Addressing (3)
Examples:
MOVC A, @A+DPTR
Where, A – Index Register, DPTR- Base Register,
C- Code/Program memory

6/9/2024 EE3404/MPMC/Unit-4 110


Instruction Formats of 8051 (1)
• The 8051has totally has 111 Instructions.

• Each instruction has 1 byte opcode.

• With 8- bit binary code, we can generate different binary


codes.

• The size of 8051 instruction is 1 to 3 bytes.

• Each instruction has 1 byte opcode.

• The remaining bytes are either data or address.

6/9/2024 EE3404/MPMC/Unit-4 111


Instruction Formats of 8051 (2)
1-Byte Instruction
Opcode

Ex: MOVC A,@A+DPTR; MOV A, Rn; JMP @A+DPTR; MOVX A,@Ri;


MOVX A,@ DRTR; CLR C; RL A; SWAP A;

2-Byte Instruction
Low byte
Opcode data/address

Ex: MOV A,#26H; PUSH direct; POP direct; ACALL addr11;


AJMP addr11; SJMP rel addr; ADDC A,#20H;

3-Byte Instruction
Low byte High byte
Opcode data/address data/address

Ex: LJMP addr16; LCALL addr16; CJNE A,#50H, rel;


DJNZ R5, loop; CJNE A,direct,rel; MOV DPTR, #data16;

6/9/2024 EE3404/MPMC/Unit-4 112


Instruction Set of 8051 (1)
✓ 8051 microcontroller has 111 instructions to perform
various operations.

✓ There are five groups of instructions/operations which


are listed below.
1) Data Transfer Instructions (28)
2) Arithmetic Instructions (24)
3) Logical Instructions (25)
4) Boolean Variable/Bit-oriented Instructions (17)
5) Program Branching Instructions (17)

6/9/2024 EE3404/MPMC/Unit-4 113


Instruction Set of 8051 (2)
Data Transfer Instructions (1)
✓ There are 28 instruction types in the data transfer type of
operations
✓ Transfer data between registers or external program memory or
external data memory.
✓ None of the flags are affected
✓ Rn any of the registers R0 to R7;
✓ Ri any of the registers R0 and R1;
✓ d8 any 8-bit immediate data (range 00H–FFH);
✓ d16 any 16-bit immediate data (range 0000H–FFFFH);
✓ a8 8-bit address. This could refer to an SFR or a data RAM
location.
6/9/2024 EE3404/MPMC/Unit-4 114
Instruction Set of 8051 (2)
Data Transfer Instructions (2)

6/9/2024 EE3404/MPMC/Unit-4 115


Instruction Set of 8051 (2)
Data Transfer Instructions (3)
Example :
Write instructions to perform the following operations:
1) Move the content of the accumulator into the R0
register
2) Load immediate 8-bit data (FFH) into the accumulator.
3) Load Data pointer with 9000H. (iv)
4) Move the content of the accumulator to external
RAM location 8000H.

6/9/2024 EE3404/MPMC/Unit-4 116


Instruction Set of 8051 (2)
Data Transfer Instructions (4)
Example: Solution
1) MOV A, R0; Move the content of accumulator into R0 register

2) MOV A, #FFH; Load immediate 8-bit data (FFH) into the accumulator.

3) MOV DPTR, #9000H; Load Data pointer with 9000H.

4) MOV DPTR, #8000; Load Data Pointer with 8000H.


MOVX @DPTR, A; Move the content of the accumulator to external
RAM location 8000H.

6/9/2024 EE3404/MPMC/Unit-4 117


Instruction Set of 8051 (3)
Arithmetic Instructions (1)
✓ There are 24 instruction types in this operations

✓ Perform addition, subtraction, multiplication, and division.

✓ Flags are affected

✓ Rn any of the registers R0 to R7;

✓ Ri any of the registers R0 and R1;

✓ d8 any 8-bit immediate data (range 00H–FFH);

✓ a8 8-bit address. This could refer to an SFR or a data RAM


location.
6/9/2024 EE3404/MPMC/Unit-4 118
Instruction Set of 8051 (3)
Arithmetic Instructions (2)

6/9/2024 EE3404/MPMC/Unit-4 119


Instruction Set of 8051 (3)
Arithmetic Instructions (3)
Example :
Write instructions to perform the following operations:

6/9/2024 EE3404/MPMC/Unit-4 120


Instruction Set of 8051 (3)
Arithmetic Instructions (4)
Example: Solution

6/9/2024 EE3404/MPMC/Unit-4 121


Instruction Set of 8051 (3)
Arithmetic Instructions (5)
Example :
Write instructions to perform the following operations:

6/9/2024 EE3404/MPMC/Unit-4 122


Instruction Set of 8051 (3)
Arithmetic Instructions (6)
Example: Solution

6/9/2024 EE3404/MPMC/Unit-4 123


Instruction Set of 8051 (4)
Logical Instructions (1)
✓ There are 25 instruction types in this operations
✓ Perform logical operations like AND, OR, XOR, NOT, Rotate, Clear,
and Swap.
✓ Only RRC and RLC instructions affect the Cy flag.
✓ The other instructions do not affect any flag.
✓ Rn any of the registers R0 to R7;
✓ Ri any of the registers R0 and R1;
✓ d8 any 8-bit immediate data (range 00H–FFH);
✓ a8 8-bit address. This could refer to an SFR or a data RAM
location.

6/9/2024 EE3404/MPMC/Unit-4 124


Instruction Set of 8051 (4)
Logical Instructions (2)

6/9/2024 EE3404/MPMC/Unit-4 125


Instruction Set of 8051 (4)
Logical Instructions (3)
RL A :Rotate Accumulator Left

RLC A :Rotate Accumulator Left through Carry

6/9/2024 EE3404/MPMC/Unit-4 126


Instruction Set of 8051 (4)
Logical Instructions (4)
RR A :Rotate Accumulator Right

RRC A :Rotate Accumulator Right through Carry

6/9/2024 EE3404/MPMC/Unit-4 127


Instruction Set of 8051 (5)
Boolean Variable/Bit-oriented Instructions (1)

✓ There are 17 instruction types in this operations

✓ It deals with bit variables.

✓ There is a special bit-addressable area in the RAM

✓ Special Function Registers (SFRs) are also bit-addressable.

✓ bit : 8-bit address of a bit which is bit addressable;

✓ rel : 8-bit signed displacement (range 128 to 127)

6/9/2024 EE3404/MPMC/Unit-4 128


Instruction Set of 8051 (5)
Boolean Variable/Bit-oriented Instructions (2)

6/9/2024 EE3404/MPMC/Unit-4 129


Instruction Set of 8051 (5)
Program Branching Instructions (1)
✓ There are 17 instruction types in this operations
✓ These instructions control the flow of program logic.
✓ addr11 = 11-bit address
✓ addr16 = 16-bit address
✓ d8 any 8-bit immediate data (range 00H–FFH);
✓ a8 8-bit address. This could refer to an SFR or a data RAM
location.
✓ rel : 8-bit signed displacement (range 128 to 127)
✓ Rn any of the registers R0 to R7;
✓ Ri any of the registers R0 and R1;
6/9/2024 EE3404/MPMC/Unit-4 130
Instruction Set of 8051 (5)
Program Branching Instructions (2)

6/9/2024 EE3404/MPMC/Unit-4 131


Simple Programming Examples (1)
# Store 8-bit immediate data (65H) into accumulator.

# Transfer the contents of B register into accumulator.

# Load 42H and 55H in registers R0 and R1 respectively.

6/9/2024 EE3404/MPMC/Unit-4 132


Simple Programming Examples (2)
# Place the contents of external memory location 8000H into
accumulator.

# Read the contents of external RAM locations 2000H and 2001H.


Place values in R5 and R6 respectively.

6/9/2024 EE3404/MPMC/Unit-4 133


Simple Programming Examples (3)
# Load 45H in external memory location 8000 H.

# Write program instructions to load a byte in memory location


9000H and increment the contents of the memory location.

6/9/2024 EE3404/MPMC/Unit-4 134


Simple Programming Examples (4)
# Subtraction of two 8-bit Numbers:
Assume one number EFH is in accumulator and other
number 45H in R0 register. After subtraction result will be
stored in R1 register.

6/9/2024 EE3404/MPMC/Unit-4 135


Simple Programming Examples (5)
# 2’s Complement of an 8-bit Number:
Assume 4FH data is immediately loaded into accumulator. Find
the 2’s complement number and Store result in 9001H memory
location

6/9/2024 EE3404/MPMC/Unit-4 136


Simple Programming Examples (6)
# Shift an 8-bit number left by two bits and store at 40H
memory location.

6/9/2024 EE3404/MPMC/Unit-4 137


Simple Programming Examples (7)
# Swap 4-MSBs with 4-LSBs in Accumulator and store in 9100H
memory location.

6/9/2024 EE3404/MPMC/Unit-4 138


8051 Microcontroller Applications (1)

▪ Keyboard and Display Interface


▪ Temperature Control System
▪ Stepper Motor Control

6/9/2024 EE3404/MPMC/Unit-4 139


Keyboard and Display Interface (1)
LCD Interfacing (1)

In recent years, the LCD has been found in widespread use


replacing LEDs (seven-segment LEDs or other multi-segment
LEDs). This is due to the following reasons:

✓ The declining prices of LCDs.

✓ The ability to display numbers, characters, and graphics

✓ Incorporation of a refreshing controller into the LCD

✓ Ease of programming for characters and graphics.

6/9/2024 EE3404/MPMC/Unit-4 140


Keyboard and Display Interface (2)
LCD Interfacing (2)
Pin Positions for Various LCDs from Optrex

6/9/2024 EE3404/MPMC/Unit-4 141


Keyboard and Display Interface (3)
LCD Interfacing (3)
LCD -14 pins.

6/9/2024 EE3404/MPMC/Unit-4 142


Keyboard and Display Interface (4)
LCD Interfacing (3)
LCD Command Codes Code Command to LCD Instruction (Hex) Register

6/9/2024 EE3404/MPMC/Unit-4 143


Keyboard and Display Interface (5)
LCD Interfacing – Operations (4)
1) Sending commands and data to LCDs with a Time Delay
✓ To send any of the commands to the LCD, make pin RS = 0
✓ For data, make RS = 1
✓ Then send a high-to-low pulse to the E pin to enable the
internal latch of the LCD
2) Sending code or data to the LCD with checking Busy Flag
✓ Put a long delay between issuing data or commands to the
LCD
✓ To monitor the busy flag before issuing a command or data to
the LCD

6/9/2024 EE3404/MPMC/Unit-4 144


Keyboard and Display Interface (6)
LCD Interfacing – Diagram (5)

6/9/2024 EE3404/MPMC/Unit-4 145


Keyboard and Display Interface (7)
LCD Instructions (1)

6/9/2024 EE3404/MPMC/Unit-4 146


Keyboard and Display Interface (8)
LCD Instructions (2)

DD RAM : Display data


RAM
CG RAM :
Character generator RAM
ACC:
CG RAM address
ADD:
DD RAM address
corresponds to the cursor
address

6/9/2024 EE3404/MPMC/Unit-4 147


Keyboard and Display Interface (9)
Assembly Language Program (1)

6/9/2024 EE3404/MPMC/Unit-4 148


Keyboard and Display Interface (10)
Assembly Language Program (2)

6/9/2024 EE3404/MPMC/Unit-4 149


Keyboard and Display Interface (11)
Keyboard Interfacing (1)
▪ At the lowest level, keyboards are organized in a matrix of rows and
columns.
▪ The CPU accesses both rows and columns through ports; therefore,
with two 8-bit ports, an 8 x 8 matrix of keys can be connected to a
microprocessor.
▪ When a key is pressed, a row and a column make contact;
otherwise, there is no connection between rows and columns.
▪ In IBM PC keyboards, a single microcontroller (consisting of a
microprocessor, RAM and EPROM, and several ports all on a single
chip) takes care of hardware and software interfacing of the
keyboard.

6/9/2024 EE3404/MPMC/Unit-4 150


Keyboard and Display Interface (12)
Keyboard Interfacing - Operations (2)
▪ Scanning and Identifying the Key
✓ 4 x 4 matrix connected to two ports.
✓ The rows are connected to an output port and the columns
are connected to an input port.
✓ If no key has been pressed, reading the input port will yield 1s
for all columns since they are all connected to high (VCC).
✓ If all the rows are grounded and a key is pressed, one of the
columns will have 0 since the key pressed provides the path to
the ground.
✓ It is the function of the microcontroller to scan the keyboard
continuously to detect and identify the key-pressed
6/9/2024 EE3404/MPMC/Unit-4 151
Keyboard and Display Interface (13)
Keyboard Interfacing – Operations (3)
▪ Grounding rows and reading the columns
✓ To detect a pressed key, the microcontroller grounds all rows by
providing 0 to the output latch, and then it reads the columns.
✓ If the data read from the columns is D3–D0 = 1111, no key has
been pressed and the process continues until a key press is
detected.
✓ However, if one of the column bits has a zero, this means that a
key press has occurred.
✓ For example, if D3–D0 = 1101, this means that a key in the D1
column has been pressed.
✓ After a key press is detected, the microcontroller will go through
the process of identifying the key.
6/9/2024 EE3404/MPMC/Unit-4 152
Keyboard and Display Interface (14)
Keyboard Interfacing (4)
4x4 Matrix Keyboard Connection to Ports

6/9/2024 EE3404/MPMC/Unit-4 153


Keyboard and
Display
Interface (15)
Keyboard
Interfacing (5)

6/9/2024 EE3404/MPMC/Unit-4 154


Keyboard and Display Interface (16)
Keyboard Interfacing (6)
4x4 Matrix Keyboard – Identification of pressed Key
Example: Identify the row and column of the pressed key for each
of the following.
(a) D3–D0 = 1110 for the row, D3–D0 = 1011 for the column
(b) D3–D0 = 1101 for the row, D3–D0 = 0111 for the column

Solution: The row and column can be used to identify the key.
(a) The row belongs to D0 and the column belongs to D2; therefore,
key number 2 was pressed.
(b) The row belongs to D1 and the column belongs to D3; therefore,
key number 7 was pressed.
6/9/2024 EE3404/MPMC/Unit-4 155
Keyboard and Display Interface (17)
Assembly Language Program (1)

6/9/2024 EE3404/MPMC/Unit-4 156


Keyboard and Display Interface (18)
Assembly Language Program (2)

6/9/2024 EE3404/MPMC/Unit-4 157


Keyboard and Display Interface (19)
Assembly Language Program (3)

6/9/2024 EE3404/MPMC/Unit-4 158


Keyboard and Display Interface (20)
Assembly Language Program (4)

6/9/2024 EE3404/MPMC/Unit-4 159


Temperature Control System (1)
▪ The microcontroller-based temperature control system can be used
for automatic control of the temperature of a plant.
▪ The temperature of the plant is measured using a temperature
sensor.
▪ The different types of temperature sensors that can be used for
temperature measurement are thermo-couples, Thermistors, PN-
junctions, IC sensors like AD590, etc.
▪ These sensors will convert the input temperature to proportional
analog voltage or current.
▪ The output signal of the sensor will be a weak signal and so it has to
be amplified using high input impedance operational amplifier.
▪ Then the analog signal is scaled to suitable level by the signal
conditioning circuit.
6/9/2024 EE3404/MPMC/Unit-4 160
Temperature Control System (2)
Interfacing Diagram

6/9/2024 EE3404/MPMC/Unit-4 161


Temperature
Control System (3)
Process – Flow
Chart

6/9/2024 EE3404/MPMC/Unit-4 162


Temperature Sensor Interfacing (1)
Introduction
▪ Transducers convert physical data such as temperature, light
intensity, flow, and speed to electrical signals.

▪ Depending on the transducer, the output produced is in the


form of voltage, current, resistance, or capacitance.

▪ For example, temperature is converted to electrical signals


using a transducer called a thermistor.

▪ A thermistor responds to temperature change by changing


resistance, but its response is not linear

6/9/2024 EE3404/MPMC/Unit-4 163


Temperature Sensor Interfacing (2)
LM34 Temperature Sensors
▪ The sensors of the LM34 series are precision integrated-circuit
temperature sensors whose output voltage is linearly proportional
to the Fahrenheit temperature.
▪ The LM34 requires no external calibration since it is internally
calibrated.
▪ It outputs 10 mV for each degree of Fahrenheit temperature.

6/9/2024 EE3404/MPMC/Unit-4 164


Temperature Sensor Interfacing (3)
LM35 Temperature Sensors
▪ The LM35 series sensors are precision integrated-circuit
temperature sensors whose output voltage is linearly proportional
to the Celsius (centigrade) temperature.
▪ The LM35 requires no external calibration since it is internally
calibrated.
▪ It outputs 10 mV for each degree of centigrade temperature.

6/9/2024 EE3404/MPMC/Unit-4 165


Temperature Sensor Interfacing (4)
Signal Conditioning & Interfacing the LM35 to the 8051
▪ Signal conditioning is widely used in the world of data acquisition.
▪ The most common transducers produce an output in the form of
voltage, current, charge, capacitance, and resistance.
▪ However, we need to convert these signals to voltage in order to
send input to an A-to-D converter.
▪ This conversion (modification) is commonly called signal
conditioning.
▪ Signal conditioning can be a current-to-voltage conversion or a
signal amplification.
▪ For example, the thermistor changes resistance with temperature
6/9/2024 EE3404/MPMC/Unit-4 166
Temperature Sensor Interfacing (5)
Signal Conditioning & Interfacing the LM35 to the 8051

Getting Data From


the Analog World

6/9/2024 EE3404/MPMC/Unit-4 167


Temperature Sensor Interfacing (6)
Signal Conditioning & Interfacing the LM35 to the 8051
▪ The change of resistance must be translated into voltages in order
to be of any use to an ADC
▪ In the case of connecting an LM35 to an ADC0848, since the
ADC0848 has 8-bit resolution with a maximum of 256 (28) steps and
the LM35/LM34) produces 10 mV for every degree of temperature
change
▪ We can condition Vin of the ADC0848 to produce a Vout of 2560 mV
(2.56 V) for full-scale output
▪ Therefore, to produce the full-scale Vout of 2.56 V for the ADC0848,
we need to set Vref = 2.56.
▪ This makes the Vout of the ADC0848 correspond directly to the
temperature as monitored by the LM35
6/9/2024 EE3404/MPMC/Unit-4 168
Temperature Sensor Interfacing (7)
Signal Conditioning & Interfacing the LM35 to the 8051

6/9/2024 EE3404/MPMC/Unit-4 169


Temperature Sensor Interfacing (8)
8051 Connection to ADC0848 and Temperature Sensor
▪ LM336-2.5 zener diode to fix the voltage across the 10K pot at 2.5V
▪ LM336-2.5 should overcome any fluctuations in the power supply.

6/9/2024 EE3404/MPMC/Unit-4 170


Temperature Sensor Interfacing (9)
Assembly Language Program (1)

6/9/2024 EE3404/MPMC/Unit-4 171


Temperature Sensor Interfacing (10)
Assembly Language Program (2)

6/9/2024 EE3404/MPMC/Unit-4 172


Stepper Motor Control (1)
Basic Concepts (1)
▪ A stepper motor is a widely used device that translates electrical
pulses into mechanical movement.
▪ In applications such as disk drives, dot matrix printers, and
robotics, the stepper motor is used for position control.
▪ Stepper motors commonly have a permanent magnet rotor (also
called the shaft) surrounded by a stator.
▪ There are also steppers called variable reluctance stepper motors
that do not have a PM rotor.
▪ The most common stepper motors have 4 stator windings that are
paired with a center-tapped common.
▪ This type of stepper motor is commonly referred to as a 4-phase or
unipolar stepper motor.
6/9/2024 EE3404/MPMC/Unit-4 173
Stepper Motor Control (2)
Basic Concepts (2)
▪ The center tap allows a change of current direction in each of the
two coils when a winding is grounded
▪ Thereby resulting in a polarity change of the stator.
▪ The stepper motor shaft moves in a fixed repeatable increment,
which allows one to move it to a precise position.
▪ This repeatable fixed movement is possible as a result of basic
magnetic theory where poles of the same polarity repel and
opposite poles attract.
▪ The stator poles are determined by the current sent through the
wire coils.
▪ As the direction of the current is changed, the polarity is also
changed causing the reverse motion of the rotor
6/9/2024 EE3404/MPMC/Unit-4 174
Stepper Motor Control (3)
Basic Concepts – Rotor Alignment (3)

6/9/2024 EE3404/MPMC/Unit-4 175


Stepper Motor Control (4)
Basic Concepts – Rotor Alignment (4)
▪ The stepper motor discussed here has a total of 6 leads: 4 leads
representing the 4 stator windings and 2 commons for the center-
tapped leads.
▪ As the sequence of power is applied to each stator winding, the
rotor will rotate.

6/9/2024 EE3404/MPMC/Unit-4 176


Stepper Motor Control (5)
Basic Concepts –Step Angle (5)
▪ It is the minimum degree of rotation associated with a single step.
▪ Various motors have different step angles.
▪ This depends on the internal construction of the motor, in
particular the number of teeth on the stator and the rotor.
▪ This is the total number of steps needed to rotate one complete
rotation or 360 degrees (e.g., 180 steps × 2 degrees = 360).
▪ Steps per second and rpm relation
The relation between rpm (revolutions per minute), steps per
revolution, and steps per second is as follows

6/9/2024 EE3404/MPMC/Unit-4 177


Stepper Motor Control (6)
Basic Concepts –Step Angle (6)

6/9/2024 EE3404/MPMC/Unit-4 178


Stepper Motor Control (7)
Basic Concepts – Normal 4-Step Sequence (7)

6/9/2024 EE3404/MPMC/Unit-4 179


Stepper Motor Control (8)
Basic Concepts : 8-Step Sequence (8)
▪ To allow for finer resolutions, all stepper motors allow an 8-step
switching sequence or half-stepping

6/9/2024 EE3404/MPMC/Unit-4 180


Stepper Motor Control (9)
Basic Concepts: Stepper Motor Specifications (9)

6/9/2024 EE3404/MPMC/Unit-4 181


Stepper Motor Control (10)
Basic Concepts: Stepper Motor Types (10)

6/9/2024 EE3404/MPMC/Unit-4 182


8051 Connection to Stepper Motor Control (1)

6/9/2024 EE3404/MPMC/Unit-4 183


8051 Connection to Stepper Motor Control (2)
▪ The four leads of the stator winding are controlled by four bits of
the 8051 port (P1.0–P1.3).
▪ However, since the 8051 lacks sufficient current to drive the
stepper motor windings, use a driver such as the ULN2003 to
energize the stator.
▪ Instead of the ULN2003, transistors as drivers, as shown in Figure.
▪ However, notice that if transistors are used as drivers, we must also
use diodes to take care of inductive current generated when the
coil is turned off.
▪ One reason that using the ULN2003 is preferable to the use of
transistors as drivers is that the ULN2003 has an internal diode to
take care of back EMF.

6/9/2024 EE3404/MPMC/Unit-4 184


8051 Connection to Stepper Motor Control (3)
Using transistors as drivers (1)
▪ Unipolar stepper motor using transistors.

▪ Diodes are used to reduce the back EMF spike created


when the coils are energized and de-energized

▪ Darlington transistors can accommodate higher voltages


and currents.

6/9/2024 EE3404/MPMC/Unit-4 185


8051 Connection to Stepper Motor Control (4)
Using transistors as drivers (2)

6/9/2024 EE3404/MPMC/Unit-4 186


8051 Connection to Stepper Motor Control (5)
Controlling Stepper Motor via Optoisolator (1)

Optoisolators are widely used to isolate the stepper motor’s EMF


voltage and keep it from damaging the digital/microcontroller system.
6/9/2024 EE3404/MPMC/Unit-4 187
8051 Connection to Stepper Motor Control (6)
Assembly Language Program (1)

▪ Change the value of DELAY to set the speed of rotation.


▪ Using single-bit instructions SETB and CLR instead of RR A to create
the sequences.
6/9/2024 EE3404/MPMC/Unit-4 188
References
• Muhammad Ali Mazidi and Janice Gillispie Mazidi, “ The
8051 Microcontroller and Embedded Systems” ,Fourth
reprint 2002.
• Ajay V Deshmukh “ Microcontrollers: Theory and
Applications” Tata McGraw- Hill Edition, Seventh Reprint
2007.

6/9/2024 EE3404/MPMC/Unit-4 189

You might also like