17ec563 M01
17ec563 M01
17ec563 M01
ON
8051
MICROCONTROLLER
(17EC563)
Ver: 1.1
Date: 9th Sept 2019
by
MOHAMED ANEES
Assistant Professor
Department of Electronics & Communication
Jain Institute of Technology, Davangere
ENGINEERING NOTES – 8051 MICROCONTROLLER (17EC563)
TABLE OF CONTENTS
NOTE:
In case of any mistakes or typo errors, please inform to mohamed.anees@hotmail.com
1.0 INTRODUCTION
A Microcontroller is a programmable
A Microprocessor is a programmable
integrated device that has computing and
integrated device that has computing and
decision capability. It has on-chip
decision. It doesn’t have any on-chip
peripherals such as RAM, ROM, I/O
peripherals.
ports, Timers, etc.
ROM
ROM RAM
RAM MICROCONTROLLER
CPU
CPU Serial
Serial
CPU RAM ROM
(Microprocessor)
(Microprocessor) Interface
Interface
SERIAL
I/O TIMERS
Timer
Timer I/O
I/O Port
Port PORT
Since memory and I/O has to be connected Since memory and I/O are present
externally, the circuit becomes large. internally, the circuit is small.
Most of the microprocessors use CISC and Microcontrollers are based on RISC &
Von-Neumann architecture. Harvard architecture.
SERIAL I/O
CLOCK TIMERS
PORT PORTS
4) Distributed
The term distributed means that embedded system may be a part of larger
systems. Many numbers of such distributed systems form a single large
embedded control unit.
6) Power concerns
Battery operated embedded systems are expected to consume minimal power.
Embedded systems working on live power should not consume much power.
7) Memory
Embedded Systems are expected to work with restricted memory. Hence the
application should be written considering all optimal techniques.
PSEN PS
G&
ion
ALE
CONT
EA
ROL DPTR
RST
PORT PORT
1
………….. 3
…………..
P2.0 P2.7 P3.0 P3.7
Figure 1: 8051 Architecture
Internal RAM
8051 has 128 bytes of internal RAM organized into three areas.
32 working registers organized as four banks. Each bank has eight registers named
R0 to R7.
16 bytes of bit addressable area.
General Purpose RAM (30h to 7Fh).
Internal ROM
8051 has 4K of internal ROM addressable as bytes from 0000h to 0FFFh.
The PC is used to address the code bytes.
Timers
The 8051 has two times/counters namely Timer 0 and Timer 1.
They can be used either as timers to generate a time delay or as counters to count
events.
Register B
It’s an 8-bit register and has address F0.
Reg. B is used with Reg. A for multiplication and division operations.
3.3.6 DPTR
DPTR is a 16-bit register.
The DPTR is made up of two 8-bit registers, namely DPH and DPL, which are used
to provide memory addresses for internal and external code access and external
data access
̅̅̅̅
𝐄𝐀
This pin is used to access external program memory (ROM).
If ̅̅̅̅
𝐄𝐀 = 1, it selects internal program memory (000h to FFFh). Beyond this address it
selects external program memory.
If ̅̅̅̅
𝐄𝐀 =0, it selects only external program memory (ROM).
̅̅̅̅̅̅̅̅
𝐏𝐒𝐄𝐍
̅̅̅̅̅̅̅ stands for “program store enable”. It remains low while fetching external program
PSEN
memory. During the internal program execution, the condition of this pin is high.
I/O PORTS
8051 has four I/O ports namely P0, P1, P2 & P3. Each port has eight input/output pins.
All the ports are bit addressable.
PORT 0 is multiplexed with lower order address lines and data lines.
PORT 2 is multiplexed with higher order address lines.
PORT 3 is multiplexed with alternate functions.
PORT 1 is the only port which is not multiplexed.
CY AC - RS1 RS0 OV - P
The program status word (PSW) register is an 8-bit register. It is also referred to as flag
register. PSW is bit addressable as PSW.0 to PSW.7
CY (Carry Flag)
The carry flag is affected by arithmetic & logical instructions.
If there is a carry from MSB bit, the CY bit is set; otherwise, it is cleared.
OV (Overflow Flag)
Overflow occurs when the result of an arithmetical operation on signed operations is too
large and cannot be stored in one register.
P (Parity Flag)
The parity flag reflects the number of 1s in the accumulator (Reg. A) Only.
Reg. A Description Parity Flag Parity Type
A = 03H
Reg. A contains even number of 1s 0 Even
(00000011)
A = 01H
Reg. A contains odd number of 1s 1 Odd
(00000001)
PORT 0 (P0)
PORT 0 has 8 I/O pins multiplexed with address and data lines. It is bidirectional
port means, it can be programmed both as input and output pin.
Port 0 is addressed with address 80H.
The pins of PORT 0 must be connected externally to a 10K ohm pull-up resistor
because PORT 0 is open drain.
When connecting an 8051 to an external memory, PORT 0 provides both address
and data. The 8051 multiplexes address and data through PORT 0 to save pins.
PORT 1
PORT 1 has 8 I/O pins. It is the only port, which is not multiplexed.
Port 1 is addressed with address 90H.
It is bidirectional port means, it can be programmed both as input and output pin.
When 1 is written to the PORT 1 latch, it acts as input. When 0 is written to the
PORT 1 latch, it acts as output.
PORT 2
PORT 2 has 8 I/O pins. It is multiplexed with higher order address lines.
Port 2 is addressed with address A0H.
It is bidirectional port means, it can be programmed both as input and output pin.
When 1 is written to the PORT 2 latch, it acts as input. When 0 is written to the
PORT 2 latch, it acts as output.
PORT 3
Consumer Appliances
o Digital Camera, DVD player, Electronic Toys, Remote Controls etc.
Home Appliances
o Refrigerators, Vacuum cleaners, washing machine, Microwave oven etc.
Office Automation
o Xerox machine, Fax machine, Modem, Printer, Scanner etc.
Industrial Automation
o Monitoring of temperature, pressure, humidity, voltage, current etc.
Medical Electronics
o ECG, EEG, X-Ray machines, Dialysis unit etc.
Computer Networking
o Bridges, Routers, Integrated Services Digital Networks (ISDN) etc.
Wireless Technologies
o Mobile phones, PDAs, palmtops etc.
Automotive Industry
Smart Cards
o Banking, Security, Telephone etc.
Telecommunication
o Mobile computing, Mobile access etc.
Instrumentation
o Digital Oscilloscope, Logic Analyzer, Spectrum Analyzer etc.
Each location contains m bits, where y is the number of data pins on the chip.
Example 1: A given memory chip has 12 address pins and 4 data pins. Find:
(a) The organization, and (b) the capacity.
Solution:
(a) This memory chip has 4096 locations (212 = 4096)
(b) Since there are total of 4K locations and each location can hold 4 bits of data. Hence
Capacity = (4K x 4) = 16 K bits.
512K/8 = 64K;
The 8051 microcontroller has 128 bytes of on-chip RAM and 4KB of on-chip ROM.
When the on-chip memory is insufficient, we go for external memory. Since 8051 has
16 bit address lines, we can access up to 64K of address space.
2) ALE PIN
The ALE pin of 8051 along with 74LS373 latch is used to demultiplex the address
and data lines AD0 – AD7.
The address A0 – A7 is latched on a positive pulse of ALE pin.
3) 𝐂𝐒
CS stands for chip select. In most of the ICs it is an active low signal.
To enable the chip (RAM / ROM), this signal should be active low.
1) 𝐄𝐀
EA stands for external access. It is used to access EXTERNAL ROM.
When EA is connected to ground, 8051 fetches instructions from external
ROM by using PSEN.
2) 𝐏𝐒𝐄𝐍
PSEN stands for “program store enable”.
Program store signal is an output control signal. It remains low while
fetching external program memory.
During the internal program execution, the condition of this pin is high.
P0 and P2 provide 16-bit address to access external memory. P0 provides the lower 8-bit
address and data (AD0 – AD7). P2 provides the upper 8-bit address (A8 – A15). Depending
upon the size, the program memory will need address line A0 – An as input. For example
for a ROM of size (8K x 8), the numbers of address lines required are 13 (A0 – A12).
Normally the chip select is derived from the unused address lines.
The demultiplexer octal latch (74LS373) is used to generate the lower address signals (A0
– A7). The ALE pin of 8051 along with 74LS373 latch is used to demultiplex the address
and data lines AD0 – AD7.
Data lines from program memory are directly connected with AD0 – AD7 pins of the
processor.
𝐏𝐒𝐄𝐍 signal from the 8051 is directly connected to the read input (𝐑𝐃) of program
memory. In some of the program memory, the read signal is designated as OUTPUT
ENABLE (𝐎𝐄).
When 𝐄𝐀 is connected to ground, 8051 fetches instructions from external ROM by using
𝐏𝐒𝐄𝐍.
The instruction MOVC A, @A+DPTR is used to read the byte from program memory.
P0 and P2 provide 16 bit address to access external memory. P0 provides the lower 8-bit
address and data (AD0 – AD7). P2 provides the upper 8-bit address (A8 – A15). Depending
upon the size, the program memory will need address line A0 – An as input. For example
for a RAM of size (4K x 8), the numbers of address lines required are 12 (A0 – A11).
Normally the chip select is derived from the unused address lines.
The demultiplexer octal latch (74LS373) is used to generate the lower address signals (A0
– A7). The ALE pin of 8051 along with 74LS373 latch is used to demultiplex the address
and data lines AD0 – AD7.
Data lines from program memory are directly connected with AD0 – AD7 pins of the
processor.
𝐑𝐃 and 𝐖𝐑 signals from data memory are directly connected to 𝐑𝐃 and 𝐖𝐑 signals of
8051.
𝐑𝐃 is an active low signal. It is used for reading from external data memory.
Since we need to interface only one chip, the unused address lines can be used as
port pins.
Since we are not using external ROM,
this pin is connected to Vcc.
Since we need to interface only one chip, the unused address lines can be used as port
pins.
In this type of problem, the unused address lines of 8051 microcontroller are used to
select the chip select. An external logic circuitry like decoder is needed for chip selection.
1) Show the neat schematic of interface of external 8K ROM and 16K RAM to 8051.
[June 12, 08M]
Solution:
The decoding logic should be designed in such a way that only one chip is selected at a
time.
STEP 1:
a) Connect the lower order address lines and data lines via latch.
CS CS
ALE
CLK
PORT 0 A0 – A7
A0 – A7
AD0 – AD7
74LS373 ROM RAM
LATCH 16K x 8
8K x 8
D0 – D7 D0 – D7 D0 – D7 D0 – D7
8051
PSEN OE
RD RD
EA WR WR
CS CS
ALE
CLK
PORT 0 A0 – A7
A0 – A7
AD0 – AD7
74LS373 ROM RAM
LATCH 16K x 8
8K x 8
D0 – D7 D0 – D7 D0 – D7 D0 – D7
8051
P2.5
A13
(A13)
PORT 2 A8 – A12
A8 – A12 A8 – A12 A8 – A12
A8 – A12
PSEN OE
RD RD
EA WR WR
𝐸𝐴 is grounded
When
A15 = 0, A14 = 0 and A13 = 1 - ROM is selected
A15 A15
P2.7 P2.7
A14
P2.6 A14
A13 P2.6
P2.5
CS CS
ALE
CLK
PORT 0 A0 – A7
A0 – A7
AD0 – AD7
74LS373 ROM RAM
LATCH 16K x 8
8K x 8
D0 – D7 D0 – D7 D0 – D7 D0 – D7
8051
P2.5
A13
(A13)
PORT 2 A8 – A12
A8 – A12 A8 – A12 A8 – A12
A8 – A12
PSEN OE
RD RD
EA WR WR
Solution:
A15
P2.7
A14 A15
P2.6 P2.7
A12 A14
P2.4 P2.6
A13
P2.3 A13 P2.5
CS CS
ALE
CLK
PORT 0 A0 – A7
A0 – A7
AD0 – AD7
74LS373 ROM RAM
LATCH 8K x 8
4K x 8
D0 – D7 D0 – D7 D0 – D7 D0 – D7
8051
P2.4
A12
(A12)
PORT 2
A8 – A11 A8 – A11 A8 – A11 A8 – A11
A8 – A11
PSEN OE
RD RD
EA WR WR
Note:
The decoding logic is not fixed. You can have your own decoding logic but make sure
that only one chip select is enabled.