Você está na página 1de 36

8051 Architecture

Ajit Samasgikar
IT Department
D t t
B.V.B.College of Engg. & Tech., Hubli

Ajit Samasgikar
Syllabus
Unit
U i –I
•Introduction to microcontrollers
RISC & CISC CPU Architectures, Harvard & Von-Neumann CPU architecture.
The 8051 Architecture: Introduction,, 8051 Microcontroller Hardware,, Input/output
p p
Pins, Ports and Circuits External Memory, Counter and Timers, Serial Data Input /
Output, Interrupts 05 hrs
•Addressing Modes and Operations
I t d ti
Introduction, Add
Addressing
i modes,
d E t
External
l data
d t Moves,
M C d Memory,
Code M R d Only
Read O l
Data Moves / Indexed Addressing mode, PUSH and POP Opcodes, Data exchanges,
Example Programs; Byte level logical Operations, Bit level Logical Operations,
Rotate and Swapp Operations,
p Example
p Programs.
g Arithmetic Operations:
p Flags,
g
Incrementing and Decrementing, Addition, Subtraction, Multiplication and Division,
Decimal Arithmetic, Example Programs. 06
hrs
•Jump and Call Instructions
The JUMP and CALL Program range, Jumps, calls and Subroutines, Interrupts and
Returns, Example Problems.
05 hrs

Ajit Samasgikar
Unit – II
Unit
•Timer / Counter Programming in 8051
Programming 8051 Timers, Counter Programming, programming timers 0 and 1
in 8051 C. 06 hrs
•8051 Serial Communication
Basics of Serial Communication, 8051 connections to RS-232, 8051 Serial
communication Programming, Programming the second serial port, Serial port
programming in C. 07 hrs

Unit – III
• Interrupts Programming
8051 Interrupts, Programming Timer Interrupts, Programming External
Hardware Interrupts, Programming the Serial Communication Interrupts, Interrupt
P i it in
Priority i the
th 8051/52,
8051/52 Interrupt
I t t programming
i in
i C.
C 06 hrs
• 8051 Interfacing and Applications
Interfacing 8051 to LCD, Keyboard, parallel and serial ADC, DAC, Stepper
motor interfacing,
interfacing DC motor interfacing and PWM.
PWM 07 hrs

Ajit Samasgikar
Why do we need to learn
Mi
Microprocessors/controllers?
/ t ll ?
• The microprocessor is the core of computer
comp ter
systems.
• Nowadays many communication,
communication digital
entertainment, portable devices, are
controlled by them.
them
• A designer should know what types of
components he needs,
needs ways to reduce
production costs and product reliable.

Ajit Samasgikar
Different aspects of a
microprocessor/controller

• Hardware :Interface to the real world


• Software
S ft :order
d how
h to t deal
d l with
ith inputs
i t

Ajit Samasgikar
The necessary tools for a
microprocessor/controller
i / ll

• CPU: Central Processing Unit


• I/O: Input
p /Output
p
• Bus: Address bus & Data bus
• Memory: RAM & ROM
• Timer
• Interrupt
• Serial Port
• P ll l Port
Parallel P
Ajit Samasgikar
Microprocessors:
General-purpose microprocessor
• CPU for Computers
• No RAM, ROM, I/O on CPU chip itself
• Example:Intel’s x86, Motorola’s 680x0

Many chips on mother’s board


Data Bus
CPU
General-
Serial
Purpose RAM ROM I/O Timer COM
Micro- Port
Port
processor
Address Bus

General-Purpose Microprocessor System

Ajit Samasgikar
Microcontroller :

• A smaller computer
• On-chip RAM, ROM, I/O ports...
• Example:Motorola
Example:Motorola’ss 6811
6811, Intel’s
Intel s 8051
8051, Zilog’s
Zilog s Z8 and PIC 16X

CPU RAM ROM


A single
g chipp
Serial
I/O Timer
COM
Port
Port
Microcontroller

Ajit Samasgikar
DIFFERENCE BETWEEN MICROCONTOLERS AND
MICROPROCESSORS

• MICROPROCESSOR • MICROCONTROLLER

• General purpose digital computer CPU • True computer on chip

• CPU consists of an ALU, PC, SP, some • CPU consists of ALU, PC, SP, registers,
working registers. RAM, ROM, interrupt circuits,parallel
Require to add RAM, ROM, memory & serial I/O, clock circuit.
decoders, counters & clock circuit.
• Used in real time applications to control
ƒ Prime use is to perform extensive data the environment or machines around it.
processing & handling
ƒ Have one or two multi
multi-byte
byte instructions
ƒ Have multi-byte instructions for
moving data from external memory to
CPU.
ƒ Have many bit handling instructions.
ƒ Have one or two types of bit handling
instructions
Ajit Samasgikar
DIFFERENCE BETWEEN MICROCONTOLERS AND
MICROPROCESSORS

• MICROPROCESSOR • MICROCONTROLLER

• No Built-in Memory • It has built in Flash Memory


(ROM/RAM)
• No IO ports
• It has its own IO ports
ƒ No Timers/Counters
• Built-in programmable timer/counter
ƒ No serial/parallel ports
• Serial / parallel ports for
communication with other devices
ƒ Von Neumann Architecture
• Harvard Architecture

Ajit Samasgikar
Embedded System

• Embedded system means the processor is embedded into that


application.
• An embedded product uses a microprocessor or microcontroller to do
one task only.
onl
• In an embedded system, there is only one application software that is
typically burned into ROM.
• Example:printer, keyboard, video game player

Ajit Samasgikar
Three criteria in Choosing a Microcontroller

1. meeting the computing needs of the task efficiently and cost


effectively
ff ti l
• 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
2 availability
2. a ailabilit of software
soft are development
de elopment tools
• assemblers, debuggers, C compilers, emulator, simulator,
technical support
3. wide availability and reliable sources of the microcontrollers.

Ajit Samasgikar
Block Diagram
External interrupts
On-chip Timer/Counter

Interrupt ROM for


On-chip Timer 1 Counter
Control program
code RAM Timer 0 p
Inputs

CPU

Bus Serial
4 I/O Ports
OSC Control Port

P0 P1 P2 P3 TxD RxD
Add
Address/Data
/D t

Ajit Samasgikar
FEATURES OF 8051 ARCHITECTURE:

9 8 Bit CPU with registers A(accumulator) & B.


9 16 bit program counter (PC) & data
pointer(DPTR).
9 8 bit program status word(PSW).
9 8 bit stack pointer(SP).
9 Internal ROM of 4K (8051).
(8051)
9 Internal RAM 128 bytes:
1 Four
1. F register
i t banks
b k eachh with
ith 8 registers.
it
2. 16 bytes addressable at bit level .
3. 80 bytes of general purpose data memory

Ajit Samasgikar
9 32 input/output pins arranged as four 8 bit port: P0-P3
9 2 sixteen bit timers/counters: T0 & T1
9 Full duplex serial data receiver/ transmitter:SBUF
9 Control registers: TCON,
TCON TMOD,
TMOD SCON,
SCON PCON,
PCON IP
IP, IE
9 2 external & 3 internal interrupt sources.
9 Oscillator & clock circuits.

Ajit Samasgikar
ALU PSW SFRs Latch Port0
RAM
A B
Latch Port1

DPTR Latch Port2


PC DPH ROM
DPL
Latch Port3

\EA System SFRs


Byte/bit add
ALE Timing IE
IP 8051
PSEN Reg. Bank 3 PCON
System
S t SBUF BLOCK
XTL1 Interrupts Reg. Bank 2 SCON
XTL2 Timers TCON DIAG
Reg.
g Bank 1 TMOD
RST TL0
Data buffers TH0
Vcc Memory control Reg. Bank 0 TL1
GND TH1
Ajit Samasgikar
MEMORY STRUCTURE OF 8051:

8051 has Harvard architecture which uses the same address in different
memories for code and data.

INTERNAL RAM :

128 Bytes, organized in 3 distinct areas

ƒ 32 bytes from 00H to 1FH that make up 32 registers, organized as 4 banks


no. 0 to 3, each with 8 registers(R0-R7).

ƒ Bit addressable area of 16 bytes occupying RAM byte addresses 20H to 2FH,
forming a total of 128 addressable bits.

ƒ A general purpose RAM area above bit area from 30H to 7FH addressable as
bytes

Ajit Samasgikar
Internal RAM
Byte Address Byte Address
1F R7 7F
1E R6
1D R5
1C R4
Bank 3 1B R3
1A R2
19 R1
18 R0
17 R7
16 R6
15 R5
14 R4
Bank 2 13 R3
12 R2
11 R1 Byte Bit
10 R0
0F R7 Address Addresses
0E R6 7F 78
2F
0D R5 77 70
2E
0C R4 6F 68
2D
0C R4 67 68
2C
Bank 1 0B R3 2B 5F 58
0A R2 57 50
2A
09 R1 4F 48
29
08 R0 47 40
28
07 R7 3F 38
27
06 R6 37 30
26
05 R5 2F 28
25
04 R4 27 20
24
Bank 0 03 R3 23 1F 18
02 R2 17 10
22
01 R1 0F 08
21
00 R0 07 00
20 30
7 0
Working Registers Bit Addressable General Purpose
Ajit Samasgikar
STACK & STACK POINTER

¾ an area of internal RAM used to store & retrieve the


d quickly.
data i kl
¾8 bit SP (stack pointer) holds an internal RAM address
called the top of the stack.
¾ SP increments before storing data on the stack &
decrements after a byte is retrieved from stack.
¾ limited in height to the size of internal RAM & is
normally placed high in the internal RAM
RAM.

SP=09 Store ADD 09 Get


d t
data data
SP=09
SP 09

SP=08 ADD 08 SP=08


SP=07 ADD 07 SP=07
Ajit Samasgikar
SPECIAL FUNCTION REGISTERS
REGISTERS:

9 most of the registers have specific functions assigned


9 each register, with the exception of the program counter
h an internal
has i l 1-byte
b address
dd assigned
i d to it
i
9 some are both bit and byte addressable
9 software instructions are generally able to specify a
register by its address, its symbolic name, or both.

Ajit Samasgikar
SPECIAL FUNCTION REGISTERS:

NAME FUNCTION RAM ADDRESS


(
(HEX)
)
• A ACCUMULATOR 0E0
• B ARITHMETIC 0F0
• DPH ADDRESSING EXTERNAL MEMORY 83
• DPL ADDRESSING EXTERNAL MEMORY 82
• IE INTERRUPT ENABLE CONTROL 0A8
• IP INTERRUPT PRIORITY 0B8
• P0 INPUT / OUTPUT PORT LATCH 80
• P1 INPUT / OUTPUT PORT LATCH 90
• P2 INPUT / OUTPUT PORT LATCH 0A0
• P3 INPUT / OUTPUT PORT LATCH 87
• PCON POWER CONTROL 0D0
• PSW PROGRAM STATUS WORD 98

Ajit Samasgikar
• SCON SERIAL PORT CONTROL 98
• SBUF SERIAL PORT DATA BUFFER 99
• SP STACK POINTER 81
• TMOD TIMER / COUNTER MODE CONTROL 89
• TCON TIMER / COUNTER CONTROL 88
• TL0 TIMER 0 LOW BYTE 8A
• TH0 TIMER 0 HIGH BYTE 8C
• TL1 TIMER 1 LOW BYTE 8B
• TH1 TIMER 1 HIGH BYTE 8D

Ajit Samasgikar
INTERNAL ROM
9 data and program memories in 8051 can be entirely
different physical memory entities, with the same address
ranges
9 occupies code address space 0000h to 0fffh, which is
the area where pprogram
g code resides
9 if the program address exceeds 0fffh, the code byte is
fetched from external program memory

Ajit Samasgikar
Addressing Modes

Ajit Samasgikar
8051 DATA ADDRESSING MODES

• 1. Register
1
• 2. Direct
• 3. Register-Indirect
Register Indirect
• 4. Immediate Data

The first three modes provide access to the


internal RAM and H/W register space, thus
can occur ini b
both
th th
the source and
dddestination
ti ti
operand fields.

Ajit Samasgikar
1.REGISTER ADDRESSING
• 8051 has FOUR banks of registers.
• Onlyy one bank visible at any
y one time.
• PSW register is used to select the bank.
• g
These 32 registers appear
pp in on chip
p RAM
memory(00-1FH)

Ajit Samasgikar
Byte Addressable Registers
Registers.
Register addressing consists of an opcode, the
operand,
p , which specifies
p which register
g to use,, is p
part of
the opcode byte.
eg. ADD A,Rn

Register Addressing
Typical example of accessing the registers are,
eg MOV R0
eg. R0,A
A ; move the accumulator into R0

Ajit Samasgikar
2 DIRECT ADDRESSING
2.DIRECT
•Direct addressing can access any on chip variable or H/W.
•Operand specifies the location in on-chip memory to use.
•The opcode is followed by a byte operand which specifies the direct
address to use
•All I/O ports and special function registers are assigned addresses
between 80H and FFH
•They are also direct addressable
addressable.
eg. MOV A,80H ; move data from PORT 0 to accumulator.

Ajit Samasgikar
3 IMMEDIATE ADDRESSING
3.
•In this operand follows the opcode which is constant.
•In 8051 assembly language , immediate addressing is signified by
using the # prefix.
•eg. MOV A,#12H
A #12H ; lloads
d 12 H iinto
t th
the accumulator.
l t

Ajit Samasgikar
4. REGISTER INDIRECT
ADDRESSING
• It is used to calculate the address of variable
in RAM while the program is running.
• R0 and d R1 off each
h register
i t b bank
k can actt as
index or pointer registers.
• The opcode specifies which register is used
to generate the Effective address for the
operand.

Ajit Samasgikar
• In 8051 assembly language, this addressing
mode uses the p prefix ‘ @
@’
eg.
MOV A,#@R0
A #@R0
This means load the accumulator with the
contents off the
h memory location
l i specified
ifi d
by R0

Ajit Samasgikar
Flags & the Program status Word(PSW)

• Other instructions can test the condition of


flags & make decisions based on the flag
states.
•They are bit addressable and grouped inside
the PSW
• Flags are 1 bit registers provided to store
the results of certain program instructions.
instructions
Ajit Samasgikar
PROGRAM STATUS WORD

CY AC F0 RS1 RS0 OV - P

Bit Symbol
y Function
7 CY Carry flag; used in arithmetic, jump, rotate, &
Boolean instruction
6 AC Auxiliary Carry flag; used for BCD arithmetic
5 FO User flag 0

Ajit Samasgikar
4. RS1 Register bank select bit 1
3
3. RS0 Register bank select bit 0
RS1 RS0
0 0 Bank 0
0 1 Bank 1
1 0 Bank 2
1 1 Bank 3
2. OV Overflow flag; used in arithmetic
instructions
1. - Reserved for future use.
0. P Parity flag

Ajit Samasgikar
The 8051 oscillator & clock
• Pins XTAL1 & XTAL2 are provided for
connecting a resonant network to form oscillator.
• Crystal freq. is the basic internal clock freq. Of
micro controller.
• 8051 can run at specified min. & max.
frequencies, typically 1 MHz to 16MHz.

Ajit Samasgikar
Oscillator Circuit & Timing

Ajit Samasgikar

Você também pode gostar