You are on page 1of 29

Microcontrollers and Embedded

Systems
Paper Code: AEIE 702
PART 1
THE 8051
MICROCONTROLLERS

Objectives

Compare and contrast microprocessors and microcontrollers


The 8051 microcontroller: a brief history
Block diagram of the 8051 family
Is 8-bit still relevant?
8052 and 8031 microcontroller
Harvard and Von Neumann architectures
Memory organization
Special function registers

Microcontrollers and Embedded


Processors

Microcontroller versus general-purpose


microprocessor

Figure: Microprocessor System Contrasted With Microcontroller System

Microcontrollers And Embedded


Systems

Microcontrollers for embedded systems

Table
Some Embedded Products
Using Microcontrollers

A brief history of the 8051

In 1980, Intel Corporation introduced an 8-bit


microcontroller called the 8051.
This microcontroller had 128 bytes of RAM, 4K
bytes of on-chip ROM, two timers, one serial port,
and four ports (each 8-bits wide) all on a single chip.
The 8051 is an 8-bit processor, meaning that the
CPU can work on only 8 bits of data at a time.
Data larger than 8 bits has to be broken into 8-bit
pieces to be processed by the CPU.

A brief history of the 8051

The 8051 has a total of four I/O ports, each 8 bits wide.
Although the 8051 can have a maximum of 64K bytes of on-chip ROM,
many manufacturers have put only 4K bytes on the chip.
This has led to many versions of the 8051 with different speeds and
amounts of on-chip ROM marketed by more than half a dozen
manufacturers.
Presently, different types of microcontroller are manufactured by different
semiconductor companies like Zilog, Motorola, Texas Instruments, Dallas
Semiconductors, Phillips, Siemens, Atmel, Microchip, Analog Device etc.

MCS 96 was the first 16 bit microcontroller launched by Intel in 1982.

Internal block diagram of 8051


microcontroller.

Input and output schematic of


8051 microprocessor

Pin-wise signal assignment of


8051 microcontroller

Is 8-bit still relevant?

n-bit the n refers to the data bus width of the CPU, and is
the maximum width of data it can handle at a time
PCs with 64-bit microprocessors are becoming common
Over 55% of all processors sold per year are 8-bit processors,
which comes to over 3 billion of them per year!*
8-bit microcontrollers are sufficient and cost-effective for many
embedded applications
More and more advanced features and peripherals are added
to 8-bit processors by various vendors
8-bit MCUs are well-suited for low-power applications that use
batteries

*Note: Statistics from Embedded.com Article ID# 9900861, Dec 2002

10

8052 microcontroller

11

The 8052 is another member of the 8051 family.


The 8052 has all the standard features of the 8051
as well as an extra 128 bytes of RAM and an extra
timer.
8052 has 256 bytes of RAM and 3 timers.
It has 8K bytes of on-chip program ROM instead of
4K bytes.

8031 microcontroller

12

This chip is often referred to as a ROM-less 8051 since it has


0K bytes of on-chip ROM.
To use this chip you must add external ROM to it.
This external ROM must contain the program that the 8031 will
fetch and execute.
The ROM containing the program attached to the 8031 can be
as large as 64K bytes.
In the process of adding external ROM to the 8031, you lose
two ports.
To solve this problem, you can add external I/O to the 8031.
Interfacing the 8031 with memory and I/O ports such as the
8255 chip will be discussed later.

Various 8051 microcontrollers

13

The 8051 is available in different memory types, such as UVEPROM, flash, and NV-RAM, all of which have different part
numbers.
The UV-EPROM version of the 8051 is the 8751.
The flash ROM version is marketed by many companies
including Atmel Corp. and Dallas Semiconductor.
The Atmel Flash 8051 is called AT89C51, while Dallas
Semiconductor calls theirs DS89C4xO (DS89C420/430/440).
The NV-RAM version of the 8051 made by Dallas
Semiconductor is called DS5000.
There is also an OTP (one-time programmable) version of the
8051 made by various manufacturers.

Harvard and Von Neumann


Architectures

14

Harvard Architecturea type of computer architecture where


the instructions (program code) and data are stored in separate
memory spaces
Example: Intel 8051 architecture

Von Neumann (or Princeton) Architectureanother type of


computer architecture where the instructions and data are
stored in the same memory space
Example: Intel x86 architecture (Intel Pentium, AMD Athlon,
etc.)

MCU Fetch-Execute Cycle

15

Fetch operationretrieves an
instruction from the location in
code memory pointed to by the
program
counter
(PC)
Execute operationexecutes
the instruction that was fetched
during the fetch operation. In
addition to executing the
instruction, the CPU also adds
the appropriate number to the
PC to point it to the next
instruction to be fetched.

Program
Counter
(PC)

Code Memory

F
e
t
c
h

CPU

To other
peripherals

Data Memory (RAM) Organization

16

Internal Data Memory space is


divided into three sections
Lower 128
Upper 128 (available in 8052
and above)
Special function register (SFR)

There are 384 bytes of memory


space physically, though the Upper
128 and SFRs share the same
addresses from location 80H to FFH.

Appropriate instructions should be


used to access each memory block

Lower 128 bytes: Register Banks, Bitaddressable area and General purpose RAM

General Purpose
RAM (80 bytes)
(scratch-pad area)

Bit-addressable
Area (16 bytes)

Register Banks
(8 bytes per
bank; 4 banks)

17

Example
# Problem
I.

II.
III.

What would be the address of bit 5 (bit 0 being LSB) of internal RAM
location 2AH?
Indicate the location of the bit having bit address 2FH.
Where is the bit E7H?

# Solution
i.
ii.

iii.

18

The direct address of bit 5 of internal RAM location 2AH is 55H.


It is bit 7 (MSB) of the byte with address 25H.
The range of bit addressable area vary from 00H to 7FH. Therefore, the
bit is outside the bit-addressable area. (E7H is MSB of accumulator).

I/O Ports and Special Function Registers


(SFRs) 128bytes

SFRs provide control and data exchange with the


microcontrollers resources and peripherals.
Registers which have their byte addresses ending with
0H or 8H are byte- as well as bit- addressable
Some registers are not bit-addressable. These include
the stack pointer (SP) and data pointer register (DPTR).
Blank location are imaginary memory locations and
therefore, physically not present.

19

Summary of SFRs and Their functions

Accumulator (ACC) and B register

Program status wordPSW

20

ACC (also referred to as A) is used implicitly by several instructions


B is used implicitly in multiply and divide operations
These registers are the input/output of the arithmetic and logic unit (ALU)
Both are bit as well as byte addressable.

Shows the status of arithmetic and logical operations using multiple bits
such as Carry
Selects the Register Bank (Bank 0 - Bank 3)
It is the only register through which the status of the of operations
performed by the CPU is reflected.

Bit details of Program status wordPSW

21

Summary of SFRs and their functions


(contd.)

22

Stack pointer (SP): It points the address of system stack where the last storage operation
has taken place.

Data pointerDPTR (DPH and DPL)

16-bit register used to access external code or data memory

Timer RegistersTH0, TL0, TH1, TL1, TMOD, TCON

Used for timing intervals or counting events

Parallel I/O Port RegistersP0, P1, P2 and P3: Each of four ports has its own register,
designated as the name of the concerned ports (P0, P1, P2 and P3). The system
communicates with these ports through these registers.

Serial Communication RegistersSBUF and SCON

Interrupt Management RegistersIP and IE


All interrupts have their individual default priorities, it may be changed through software by
programming the IF.

Power Control RegisterPCON: It is used for power management purpose.

The 8051 Assembly Language

23

Data transfer instructions


Addressing modes
Data processing (arithmetic and logic)
Program flow instructions

Data transfer instructions

MOV dest, source


Stack instructions
PUSH byte

POP byte

;increment stack
;move byte
;move from stack
;decrement

pointer,
on stack
to byte,
stack pointer

Exchange instructions
XCH a, byte
XCHD a, byte

24

dest source

;exchange accumulator and byte


;exchange low nibbles of
;accumulator and byte

Addressing modes

Addressing mode is the way to locate the target data or operand.

Immediate Mode specify data by its value


mov R4, #11h

;put 11hex in the R4


register
;R4 = 00010001

mov DPTR,#7521h

;put 7521 hex in DPTR


;DPTR = 0111010100100001

25

Addressing modes:
Register Addressing
Register Addressing either source or destination is one of CPU
register
MOV R0,A
MOV A,R7
ADD A,R4
ADD A,R7
MOV DPTR,#25F5H
MOV R5,DPL
MOV R4,DPH

Note that MOV R4,R7 is incorrect


26

Direct Mode specify data by its 8-bit address


Usually for 30h-7Fh of RAM
MOV A, 70h
MOV 56h,A
MOV 0D0h,A

27

; copy contents of RAM at 70h to A


; put contents of a at 56h
; put contents of a into PSW

Addressing modes: Register Indirect the address


of the source or destination is specified in registers

Uses registers R0 or R1 for 8-bit address:


MOV A,@R1

Uses DPTR register for 16-bit addresses:


mov dptr, #9000
movx a, @dptr

; dptr 9000h
; a M[9000]

Note that 9000 is an address in external memory

28

Addressing modes: Register Indexed Mode


source or destination address is the sum of the
base address and the accumulator(Index)

Base address can be DPTR or PC


mov dptr, #4000h
mov a, #5
movc a, @a + dptr

;a M[4005]

Base address can be DPTR or PC


ORG 1000h
1000
1002
1003

29

mov a, #5
movc a, @a + PC
Nop

;a M[1008]

Table Lookup
MOVC only can read internal code memory

You might also like