Вы находитесь на странице: 1из 40

The 8051

Microcontroller

Microcontroller
A micro-controller is a very powerful
device, which is capable of executing a
series of pre-programmed tasks and
interacting with other hardware devices
Being packed in a tiny integrated
circuit (IC) whose size and weight is
usually negligible,
It is becoming the perfect controller for
robots or any machines requiring some
kind of intelligent automation

Microcontroller
A single microcontroller can be sufficient to
control a small mobile robot, an automatic
washer machine or a security system.
Any microcontroller contains a memory to
store the program to be executed,
Number of input/output lines that can be
used to interact with other devices, like
reading the state of a sensor or controlling
a
motor.

Microcontroller
Most recent microcontrollers are 'In
System Programmable',
End user can modify the program being
executed, without removing the
microcontroller from its place.

Three criteria in Choosing a


Microcontroller
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
Noise of environment
Power consumption

availability of software development tools


assemblers, debuggers, C compilers, emulator, simulator,
technical support

wide availability and reliable sources of the


microcontrollers

Intel, Atmel, Philips / Signe tics, Infineon, Dallas Semi/ Maxim

8051 Basic Component


4K bytes internal ROM
128 bytes internal RAM
Four 8-bit I/O ports (P0 - P3).
Each one having 8 I/O lines
Most of the ports have dual fn.
1st- Perform I/O operations
2nd- implement special features of the
microcontroller like
counting external pulses,
interrupting the execution of the program according to
external events,
performing serial data transfer
connecting the chip to a computer to update the software.

8051 Basic Component

Two 16-bit timers/counters


One serial interface
64k external memory for code
64k external memory for data
210 bit addressable

Block Diagram
External Interrupts

Interrupt
Control

4k
ROM

128 bytes
RAM

Bus
Control

4 I/O Ports

Timer 0
Timer 1

CPU

OSC

P0 P2 P1
Addr/Data

Serial

P3

TXD RXD

Functional diagram

Microcontroller Arch.

The CPU has many important registers


The Program Count (PC) always holds the code memory
location of next instruction

It fetches instructions from the code memory into


the instruction Register (IR)
Analyzes the opcode of the instruction, updates
the PC to the location of next instruction
Fetches the operand from the data memory and
Finally performs the operation in the ArithmeticLogic Unit (ALU) within the CPU

Contd.
The B register is a register just for
multiplication and division operation which
requires more register spaces for the product
of multiplication and the quotient and the
remainder for the division.
The immediate result is stored in the
accumulator register (Acc) for next operation
and the Program Status Word (PSW) is
updated depending on the status of the
operation result

Watchdog Timer
flawless functioning of the microcontroller during its run-time
What if uc stops working or works incorrectly due to interference?
PC => reset but ES => no reset button since no human intervention
Watchdog Block - in fact another free-run counter
SW program needs to write a zero in every time it executes correctly.
If SW "stuck", zero will not be written in
counter alone will reset the microcontroller upon achieving its
maximum value.
This will result in executing the program again, and correctly this
time around.
an important element of every program to be reliable without man's
supervision

WDT Reset
WDT available in form of a timer
Since no user intervention in embedded apps, WDT is used to bring the
system back to initial state on software bug or any other interference

Ex: ATM if key is not pressed for 2 seconds WDT resets the system and
the card is ejected

Memory types
RAM and EEPROM
RAM is used to store variable during
program execution
EEPROM memory is used to store the
program itself,

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 some of the 8051 Family Members

ROM

RAM

Timer

8051

4k

128

8031

128

8751

4k eprom

128

8052

8krom

256

8032

256

8752

8k eprom

256

8051 Internal Block Diagram

8051
Schematic
Pin out

8051
Foot Print

P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
RST
(RXD)P3.0
(TXD)P3.1
(INT0)P3.2
(INT1)P3.3
(T0)P3.4
(T1)P3.5
(WR)P3.6
(RD)P3.7
XTAL2
XTAL1
GND

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

8051
(8031)
(8751)
(8951)

40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21

Vcc
P0.0(AD0
)P0.1(AD1)
P0.2(AD2
)P0.3(AD3)
P0.4(AD4)
P0.5(AD5)
P0.6(AD6)
P0.7(AD7)
EA/VPP
ALE/PROG
PSEN
P2.7(A15)
P2.6(A14
)P2.5(A13
)P2.4(A12
)P2.3(A11)
P2.2(A10)
P2.1(A9)
P2.0(A8)

IMPORTANT PINS (IO Ports)


One of the most useful features of the 8051 is that it contains four I/O ports (P0 P3)
Each port can be used as input or output (bi-direction)

Port 0
pins 32-39 P0.0 P0.7

8-bit R/W - General


Purpose I/O
Or acts as a multiplexed
low byte address and
data bus for external
memory design

IMPORTANT PINS (IO Ports)

Port 1
pins 1-8
P1.7

P1.0

Only 8-bit R/W General Purpose I/O

IMPORTANT PINS (IO Ports)

Port 2
pins 21-28 P2.0
P2.7

8-bit R/W General


Purpose I/O
Or high byte of
the address
bus for
external
memory
design

IMPORTANT PINS (IO Ports)

Port 3
pins 10-17 P3.0
P3.7

General Purpose
I/O
if not using any of
the internal
peripherals (timers)
or external
interrupts.

Port 3 Alternate Functions

IMPORTANT PINS

PSEN (out): Program Store Enable, the read signal for


external program memory (active low).
This is an output pin and is connected to the OE pin of the ROM.

EA (in): External Access Enable, active low to access external


program memory locations 0 to 4K

There is no on-chip ROM in 8031 and 8032 .


The /EA pin is connected to GND to indicate the code is stored externally.
/PSEN ALE are used for external ROM.
For 8051, /EA pin is connected to Vcc.

ALE (out): Address Latch Enable, to latch address outputs at


Port0 and Port2
It is an output pin and is active high.
8051 port 0 provides both address and data.

Pins of 8051
Vcc pin 40

Vcc provides supply voltage to the chip.


The voltage source is +5V.

GND pin 20 ground

XTAL1 & XTAL2: Crystal inputs for internal


oscillator.

XTAL1 and XTAL2 pins 19,18

These 2 pins provide external clock.

XTAL Connection to 8051

Using a quartz crystal oscillator


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

Machine cycle
Find the machine cycle for
(a) XTAL = 11.0592 MHz
(b) XTAL = 16 MHz.
Note: One machine cycle duration is the 1/12th of the
frequency of the crystal attached to the controller.
For example, if the frequency of the crystal is 12 MHz,
then the frequency for Timer will be 1MHz (1/12 of crystal
frequency)
Hence the time (T = 1/f) taken by the Timer to count by
one is 1s (1/1MHz).
Similarly if an 11.0592 MHz crystal is used, operating
frequency of Timer is 921.6 KHz and the time period is
1.085 s.

Machine Cycle
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

Pins of 8051
RST pin 9 reset
input pin and active high normally low .

The high pulse must be high at least 2


machine cycles.
power-on reset.

Upon applying a high pulse to RST, the


microcontroller will reset and all values in
registers will be lost.

On-Chip Memory
Internal RAM

Registers
1F

Bank 3

Four Register Banks


Each bank has R0-R7
Selectable by psw.2,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

Ex)
Mov A,R5
mov A, 05h

Register Banks
Active bank selected by PSW [RS1,RS0]
bit
Permits fast context switching
interrupt service routines (ISR).

in

Bit Addressable Memory


20h 2Fh

(16 locations * 8-bits = 128


bits)
Bit addressing:
mov C, 67h

General Memory
Address from
30h 7fh
Addressed by
byte

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 SPRs

Bit Addressable RAM

Figure 26
Summary
of the
8051 onchip data
memory
(Special
Function
Registers)

Registers
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