Você está na página 1de 55

MICROCONTROLLER

8051

OUTLINE

What is microcontroller?
What are different types of microcontroller?
How to select controller for a given application?
8051 internal architecture
8051 pinout & pin description
8051 architecture details
8051 assembly programming
8051 addressing modes
8051 Timer,Interrupt,serial port programming

Intruduction

Microprocessor = CPU on a single chip.

Micro-computer = small computer

ALU + registers + control +


uP + I/O + memory + peripheral +

Microcontroller (uC)

u-Computer on a single chip of silicon

Microcontrollers
Memory
CPU

ROM

RAM

I/O

A single chip

Subsystems:
Timers, Counters, Analog
Interfaces, I/O interfaces

Microcontroller :

A microprocessor, and RAM, ROM, I/O ports, and


timer on a single chip. Also called MCU, , uC
Computer on a chip
Also called MCU (MicroController Unit)
Usually not as powerful as general purpose
microprocessor
Low power consumption, small in size, low cost.
A lot of MCUs are application specific (as against the
general purpose microprocessor).C

Basic Microprocessor Systems


A Microprocessor System
Contains the same 6 basic components:
Arithmetic logic unit (ALU)
Register array
Control unit
Memory
Input unit
Output unit

MICROPROCESSOR

Microprocessor: a CPU on a single


integrated chip (IC)
a special type of CPU
The brain of a computer
E.g.:
8086, 80286, 80386, 80486, Pentium,
Core 2 Duo, Core 2 Quad, K5, K6,
Atholon, Atholon 64, Opteron, Phenon,
PowerPC G4, PowerPC G5, Xenon,
Broadway, Cell,
Contains no RAM, no ROM, no I/O
ports.

Difference between P and C


Sr. No

Several Instructions for moving


Data from ext. memory to CPU.

One or two
instructions for
moving the data
from ext memory
to
CPU.
In C
large number
of pins are multi
functioned.

In P few pins are multi


functioned.

Designer can decide on the amount


of ROM, RAM and I/O ports.

Fixed program and


data memory.

Uses different ICs for memory and


I/O

Inbuilt Memory and


I/O.

No Inbuilt timer.

Inbuilt timer is
there.

uCs

Many uCs are existing right now.


8051, 68HC11, MSP430, ARM series, and etc.

We may widely divide it with

how it is designed (RISC/CISC architecture)

Manufacturer (Atmel, Intel, Microchip, Philips,)

ROM technology (Programming Serial/Parallel)

RAM/ROM capacity

Other features (ADC/DAC, WatchDog, timer/counter, Number


of IO pin

Common Microcontrollers
Atmel
ARM
Intel
8-bit
8XC42
MCS48
MCS51
8xC251
16-bit
MCS96
MXS296
National Semiconductor
COP8
Microchip
12-bit instruction PIC
14-bit instruction PIC
PIC16F84
16-bit instruction PIC
NEC

Motorola
8-bit
68HC05
68HC08
68HC11
16-bit
68HC12
68HC16
32-bit
683xx
Texas Instruments
TMS370
MSP430
Zilog
Z8
Z86E02

How do we decide which MCU to use?


Speed
Power consumption
Amount of RAM and ROM on chip
Number of I/O pins
Cost per unit
Packaging

Three criteria in Choosing a Microcontroller


1.

2.

3.

Meeting the computing needs of the task efficiently and cost


effectively

speed, the amount of ROM and RAM, the number of I/O


ports and timers, size, packaging, power consumption

easy to upgrade

cost per unit


Availability of software development tools

assemblers, debuggers, C compilers, emulator, simulator,


technical support
Wide availability and reliable sources of the microcontrollers.

Different architectures
One shared memory for instructions (program) and
data with one data bus and one address bus
between processor and memory. Instructions and
data have to be fetched in sequential order (known
as the Von Neumann Bottleneck), limiting the
operation bandwidth.
simpler than that of the Harvard architecture.
mostly used to interface to external memory.

Basic Microprocessor Systems


Harvard architecture uses physically separate memories for their
instructions and data, requiring dedicated buses for each of them.
Instructions and operands can therefore be fetched simultaneously.
Different program and data bus widths are possible, allowing
program and data memory to be better optimized to the
architectural requirements.
E.g.: If the instruction format requires 14 bits then program bus and memory can
be made 14-bit wide, while the data bus and data memory remain 8-bit wide.

8051 Basic Component

4K bytes internal ROM


128 bytes internal RAM
Four 8-bit I/O ports (P0 - P3).
Two 16-bit timers/counters
One serial interface
CPU
I/O
Port

RAM ROM
Serial
Timer COM
Port

A single chip
Microcontroller

Block Diagram
External Interrupts

Interrupt
Control

Timer 1
Timer 2

4k
ROM

128 bytes
RAM

Bus
Control

4 I/O Ports

CPU

OSC

P0 P2 P1
Addr/Data

P3

Serial

TXD RXD

Other 8051 featurs

only 1 On chip oscillator (external crystal)

6 interrupt sources (2 external , 3 internal, Reset)

64K external code (program) memory(only read)PSEN

64K external data memory(can be read and write) by


RD,WR

Code memory is selectable by EA (internal or external)

We may have External memory as data and code

Comparison of the 8051 Family


Members
ROM type

no ROM
mask ROM
EPROM
Flash EEPROM

89xx

8031
80xx
87xx
89xx

8951
8952
8953
8955
898252
891051
892051

Example (AT89C51,AT89LV51,AT89S51)

AT= ATMEL(Manufacture)
C = CMOS technology
LV= Low Power(3.0v)

Comparison of the 8051 Family


Members
89XX

ROM

RAM

Timer

Int

IO pin

Other

8951

4k

128

32

8952

8k

256

32

8953

12k

256

32

WD

8955

20k

256

32

WD

898252

8k

256

32

ISP

891051

1k

64

16

AC

892051

2k

128

16

AC

Source

WD: Watch Dog Timer


AC: Analog Comparator
ISP: In System Programable

8051 Internal Block Diagram

8051
Schematic
Pin out

Important Pins (IO Ports)

One of the most useful features = 4 I/O ports (P0 - P3)


Port 0 :-P0 = (P0.0 - P0.7)
8-bit R/W - General Purpose I/O
low byte address and data bus for external memory
Port 1 :- P1= (P1.0 - P1.7)
Only 8-bit R/W - General Purpose I/O
Port 2 :- P2 = (P2.0 - P2.7)
8-bit R/W - General Purpose I/O
high byte address for external memory
Port 3:- P3 = (P3.0 - P3.7)
General Purpose I/O
Timers(T0,T1) ext. int (INT0, INT1) Serial (TXD, RXD)RD,WR
Each port can be used as input or output (bi-direction)

Port 3 Alternate Functions

Hardware Structure of I/O Pin


Read latch

B2

Vcc
Internal
Pull-Up

Internal CPU
bus

Write to latch

Clk

P1.X
pin

P1.X
M1

B1
Read pin

Hardware Structure of I/O Pin

Each pin of I/O ports


Internally connected to CPU bus
A D latch store the value of this pin

Write to latch 1 write data into the D latch

2 Tri-state buffer

B1: controlled by Read pin

B2: controlled by Read latch

Read pin 1 really read the data present at the pin


Read latch 1 read value from internal latch

A transistor M1 gate

Gate=0: open
Gate=1: close

Writing 1 to Output Pin P1.X


Read latch

Vcc

B2

1. write a 1 to the pin


Internal CPU
bus

Write to latch

Clk

2. output pin is
Vcc
P1.X
pin

P1.X

B1
Read pin

Internal
Pull-Up

M1

output 1

Writing 0 to Output Pin P1.X


Read latch

Vcc

B2

1. write a 0 to the pin


Internal CPU
bus

Write to latch

Clk

2. output pin is
ground
P1.X
pin

P1.X

B1
Read pin

Internal
Pull-Up

M1

output 0

Reading High at Input Pin


Read latch

1.

write a 1 to the pin MOV


P1,#0FFH
Internal CPU bus

Vcc

B2

Clk

Q
0

B1
Read pin
3. Read pin=1 Read latch=0

2. MOV A,P1
external pin=High
P1.X pin

Q
P1.X

Write to latch

Internal
Pull-Up

1
M1

Reading Low at Input Pin


Read latch
1.

Vcc

write a 1 to the pin

Internal
Pull-Up

MOV P1,#0FFH
Internal CPU bus

2. MOV A,P1

B2

P1.X
Write to latch

Clk

M1

B1
Read pin
3. Read pin=1 Read latch=0
8051 IC

external pin=Low

P1.X pin

Important Pins

PSEN (out): Program Store Enable

Read for External Code Memory (active low)

ALE (out): Address Latch Enable

to latch address outputs at Port0 and Port2

EA (in): External Access Enable

to access external program memory 0 to 4K (active low)

RXD,TXD: UART pins for serial I/O on Port 3


Vcc pin 40 : +5V (3~5V for 89LV51)
GND pin 20 : ground
XTAL1 , XTAL2 pins 19,18
RST pin 9 reset (active high)

Crystal Connection to 8051

Using a quartz crystal oscillator


We can observe the frequency on the XTAL2
C2
XTAL2
30pF
C1
XTAL1
30pF
GND

External Clock Source

Using a TTL oscillator


XTAL2 is unconnected.
N
C
EXTERNAL
OSCILLATOR
SIGNAL

XTAL2

XTAL1

GND

Machine cycle
Machine Cycle Freq.=1/12 XTAL

Find the machine cycle for


(a) XTAL = 11.0592 MHz
(b) XTAL = 16 MHz.

Solution:
(a) 11.0592 MHz / 12 = 921.6 kHz;
machine cycle = 1 / 921.6 kHz = 1.085 s
(b) 16 MHz / 12 = 1.333 MHz;
machine cycle = 1 / 1.333 MHz = 0.75 s

Power-On Reset
Vcc

31
10 uF

30 pF

9
10 K

at least 2 machine cycles

EA/VPP
X1

X2
RST

Registers Reset Value


Register
PC
ACC
B
PSW
SP
DPTR
RAM are all zero

Reset Value
0000
00
00
00
07
0000

Types of Memory
FFFFh

DATA

Chip 8051

Memory
(up to 64KB)

Internal RAM

SFRs

External

RAM

0000h

FFFFh

External
CODE

Internal code
Memory

Memory
(up to 64KB)

(EEPROM)
0000h

ROM

Types of Memory

External Code Memory (64k)


External RAM Data Memory (64k)
Internal Code Memory

4k,8k,12k,20k

ROM, EPROM, EEPROM


Internal RAM

First 128 bytes:


00h to 1Fh
Register Banks
20h to 2Fh
Bit Addressable RAM
30 to 7Fh
General Purpose RAM

Next 128 bytes:


80h to FFh
Special Function Registers

Memory Arrays

RAM (Volatile)

Read from and write to RAM


Used for Data and Program Storage

ROM (Non volatile)

Only read from ROM


Used for Program Storage only

Also store Constant data.

Special program stored in ROM

Boot Program or Loader Program

This is the program that is executed when the microcontroller is


reset

Memory Arrays

Two major types


Volatile
Data are lost when power is removed
E.g.
SRAM Static Random Access Memory
DRAM Dynamic Random Access Memory
Generically referred to as RAM (Random Access Memory)
Although non-volatile RAM exists as well
Non-Volatile
Data are retained when power is removed
E.g.
EEPROM Electrically Erasable Programmable
Read Only Memory
EPROM
- Erasable Read Only Memory
Generically referred to as ROM (Read Only Memory)

External Memory Access

/EA pin 31 external access

/PSEN pin 29 program store enable

/EA=0 indicates that code is stored externally.


/PSEN ALE are used for external ROM.
For 8051 internal code, /EA pin is connected to Vcc.
/ means active low.
Output- connected to OE of ROM.
Read signal fetch from ROM

ALE pin 30 : address latch enable

It is an output pin and is active high

8051 port 0 provides both address and data

The ALE pin is used for de-multiplexing the address and


data by connecting to the G pin of the 74LS373 latch.

Address Multiplexing for


External Memory (code)

Accessing External Data RAM

Overlap External Code and Data


Spaces

Overlap External Code and Data


Spaces
Allows the RAM to be
written as data memory
read as data memory
Read code memory.

This allows a program to be


downloaded from outside into the RAM as data, and
executed from RAM as code.

On-Chip Memory Internal RAM

General Purpose Register


1F

Bank 3
18
17

Bank 2
10
0F

Bank 1
08
07
06
05
04
03
02
01
00

R7
R6
R5
R4
R3
R2
R1
R0

Bank 0

4 Register Banks
Each bank has R0-R7
Selectable by PSW.2,3

Bit Addressable Memory


2F

7F

78

2E
2D
2C
2B
2A
29
28
27
26
25
24
23

1A

22
21
20

10
0F
07

08
06

05

04

03

02

01

00

20h 2Fh
(16 locations 8-bits = 128 bits)

Special Function Registers


DATA registers
CONTROL registers
Timers
Serial ports
Interrupt system
Analog to Digital converter
Digital to Analog converter
Etc.

Addresses 80h FFh


Direct Addressing used
to access SFRs

Program Status Word (PSW)

8051 CPU Registers


A
(Accumulator)
B
PSW (Program Status Word)
SP
(Stack Pointer)
PC
(Program Counter)
DPTR (Data Pointer)

Used in assembler
instructions

Registers
SP
A
B
R0

DPTR

DPH

DPL

R1
R2

PC

PC

R3
R4
R5
R6
R7

Some 8-bit Registers


of the 8051

Some 8051 16-bit Register

Stack in the 8051

The register used to access


the stack is called SP
(stack pointer) register.

7FH
Scratch pad RAM
30H

The stack pointer in the


8051 is only 8 bits wide,
which means that it can
take value 00 to FFH.
When 8051 powered up,
the SP register contains
value 07.

2FH
Bit-Addressable RAM
20H
1FH
18H
17H
10H
0FH
08H
07H
00H

Register Bank 3
Register Bank 2
Register Bank 1( Stack)
Register Bank 0

Review

What is microcontroller?
What are different vendors?
What are factors differentiating uc form each
other?
How to select uc for developing application?
What is there inside 8051?
What are pins of 8051?How they function?

Você também pode gostar