0% found this document useful (0 votes)
27 views49 pages

8051 Microcontroller Overview and Features

An embedded system is a microprocessor-based system designed for specific tasks, often integrated into larger devices, and can include microcontrollers or digital signal processors. The 8051 microcontroller is highlighted for its features, applications across various fields like telecommunications and medical equipment, and its internal architecture including ROM, RAM, and I/O ports. The document also discusses assembly language instructions and addressing modes relevant to programming the 8051 microcontroller.

Uploaded by

N Mohamed Athil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views49 pages

8051 Microcontroller Overview and Features

An embedded system is a microprocessor-based system designed for specific tasks, often integrated into larger devices, and can include microcontrollers or digital signal processors. The 8051 microcontroller is highlighted for its features, applications across various fields like telecommunications and medical equipment, and its internal architecture including ROM, RAM, and I/O ports. The document also discusses assembly language instructions and addressing modes relevant to programming the 8051 microcontroller.

Uploaded by

N Mohamed Athil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Embedded system(8051 Microcontroller)

Presentation
by
Sanjay Mandawariya
(7th SEM ECE)
WHAT IS EMBEDDED SYSTEMS?

• An Embedded System is a microprocessor based system that


is embedded a subsystem, in a large system (which may or
not may be a computer system).
• It is embedded as part of a complete device often including
hardware and mechanical parts.
• Embedded systems contain processing cores that are typically
either microcontrollers or digital signal processors (DSP).
• The embedded system is dedicated to specific tasks, design
engineers can optimize it to reduce the size and cost of the
product and increase the reliability and performance.
HISTORY
• Father of Embedded system is Spikes, he used his
first embedded technology in toilets to clean his
back...
• One of the first recognizably modern embedded
systems was the Apollo Guidance Computers
developed by Charles Stark Draper at the MIT
Instrumentation Laboratory
KEY FEATURES OF MICROCONTROLLER

• High Integration of Functionality


• Easy to Use
• Field Programmability
• Flexibility
• Some time Microcontroller are also called
single-chip computers
APPLICATIONS
• Telecom (Mobile phone, modems, routers. )
• Automotive application (Braking system, Traction control)
• Domestic application (Security system , television ,washing machines ,
microwave ovens)
• Robotic (Fire fighting robot, Automatic floor cleaner, robotic arm)
• Aerospace application (Flight control system, Engine controllers)
• Medical equipment (ECG monitors, Pacemakers, MRI scanners)
• Defense system (Radar systems, Radio system)
• Office Automation (Laser printers, Fax machines, Pagers)
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 RAM ROM


A single chip
I/O Serial Microcontroller
Timer COM
Port Port
Block Diagram
External Interrupts

Interrupt 4k 128 bytes Timer 1


Control ROM RAM Timer 2

CPU

OSC Bus
4 I/O Ports Serial
Control

P0 P2 P1 P3 TXD RXD
Addr/Data
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
availability of software development tools
assemblers, debuggers, C compilers, emulator, simulator, technical
support
wide availability and reliable sources of the microcontrollers
8051 Internal Block Diagram
P1.0 1 40 Vcc

8051 P1.1
P1.2
2
3
39
38
P0.0(AD0
)P0.1(AD1)

Foot Print
P1.3 4 37 P0.2(AD2
P1.4 5 36 )P0.3(AD3)
P1.5 6 35 P0.4(AD4)
P1.6 7 34 P0.5(AD5)
P1.7 8 8051 33 P0.6(AD6)
RST 9 (8031) 32 P0.7(AD7)
10 (8751) 31 EA/VPP
11 (8951) 30 ALE/PROG
12 29 PSEN
13 28 P2.7(A15)
(T0)P3.4 14 27 P2.6(A14
(T1)P3.5 15 26 )P2.5(A13
(WR)P3.6 16 25 )P2.4(A12
(RD)P3.7 17 24 )P2.3(A11
XTAL2 18 23 )P2.2(A10)
XTAL1 19 22 P2.1(A9)
GND 20 21 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)
 Port 0 ( pins 32-39 ): P0 ( 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

 Port 1 ( pins 1-8 ) : P1 ( P1.0 ~ P1.7 )


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

 Port 2 ( pins 21-28 ): P2 ( P2.0 ~ P2.7 )


 8-bit R/W - General Purpose I/O
 Or high byte of the address bus external for memory design

 Port 3 ( pins 10-17 ): P3 ( P3.0 ~ P3.7 )


 General Purpose I/O
 if not using any of the internal peripherals (timers) or external interrupts.
 Each port can be used as input or output (bi-direction)
Pins of 8051
 Vcc ( pin 40 ): Vcc provides supply voltage to the chip.
The voltage source is +5V.
 GND ( pin 20 ): ground
 XTAL1 & XTAL2 ( pins 19,18 ): These 2 pins provide external
clock.
PSEN (out pin 29): Program Store Enable, the read signal for external
program memory (active low).

ALE (out pin 30): Address Latch Enable, to latch address outputs at Port0 and Port2

EA (in pin 30): External Access Enable, active low to access external program
memory locations 0 to 4K

RXD,TXD (pin 10,11) : UART pins for serial I/O on Port 3

RST ( pin 9 ): reset

/EA ( pin 31 ): external access (“/” means active low)

/PSEN ( pin 29 ): program store enable(“/” means active low)


Registers
1F

Bank 3
Four Register Banks
Each bank has R0-R7
18 Selectable by psw.2,3
17

Bank 2

10
0F

Bank 1

08
07 R7
06 R6
05 R5
04
03
R4
R3
Bank 0
02 R2
01 R1
00 R0
Special Function Registers

DATA registers

CONTROL registers
Timers
Serial ports
Interrupt system
Analog to Digital converter
Digital to Analog converter
Etc.
8051 CPU Registers
A (Accumulator)
B
PSW (Program Status Word)
SP (Stack Pointer)
PC (Program Counter)
DPTR (Data Pointer)

Used in assembler instructions


Registers
A

B
R0
DPTR DPH DPL
R1

R2 PC PC
R3

R4 Some 8051 16-bit Register


R5

R6

R7

Some 8-bit Registers


of the 8051
The 8051
Assembly Language
Overview

• Data transfer instructions


• Addressing modes
• Data processing (arithmetic and logic)
• Program flow instructions
Data Transfer Instructions
• MOV dest, source dest  source
• Stack instructions
PUSH byte ; increment stack pointer
;move byte on stack
POP byte ; move from stack to byte
;decrement stack pointer

• Exchange instructions
XCH a, byte ;exchange accumulator and byte
XCHD a, byte ;exchange low nibbles of
;accumulator and byte
Addressing Modes
Immediate Mode – specify data by its value

mov A, #0 ;put 0 in the accumulator


;A = 00000000

mov R4, #11h ;put 11hex in the R4 register


;R4 = 00010001

mov B, #11 ;put 11 decimal in b register


;B = 00001011

Immediate Mode – continue

MOV DPTR,#7521h
MOV DPL,#21H
MOV DPH, #75
Addressing Modes
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 R,DPH

Note that MOV R4,R7 is incorrect


Addressing Modes
Direct Mode – specify data by its 8-bit address
Usually for 30h-7Fh of RAM
Mov a, 70h ; copy contents of RAM at 70h to a
Mov R0,40h ; copy contents of RAM at 70h to a
Mov 56h,a ; put contents of a at 56h to a
Mov 0D0h,a ; 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 psw, #0 ; use register bank 0
mov r0, #0x3C
mov @r0, #3 ; memory at 3C gets #3
; M[3C]  3
Uses DPTR register for 16-bit addresses:
mov dptr, #0x9000 ; dptr  9000h
movx a, @dptr ; a  M[9000]

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
SFRs Address
 B – always direct mode - except in MUL & DIV
0703 8500F0 mov b,00h
0706 8500F0 mov 0f0h,00h
0709 8CF0 mov b,r4
070B 8CF0 mov 0f0h,r4

 P0~P3 – are direct address


0704 F580 mov p0,a
0706 F580 mov 80h,a
0708 859080 mov p0,p1

 Also other SFRs (pcon, tmod, psw,….)


8051 Instruction Format
 immediate addressing
Op code Immediate data
add a,#3dh ;machine code=243d
 Direct addressing
op code Immediate data
mov r3,0E8h ;machine code=ABE8
 Register indirect addressing
op code
mov a, @Ri ; i = 0 or 1
 Relative Addressing
here: sjmp here ;machine code=80FE(FE=-2)
Range = (-128 ~ 127)
Stack(push,pop)
Stack-oriented data transfer
 Only one operand (direct addressing)
 SP is other operand – register indirect - implied
 Direct addressing mode must be used in Push and Pop

mov sp, #0x40 ; Initialize SP


push 0x55 ; SP  SP+1, M[SP]  M[55]
; M[41]  M[55]
pop b ; b  M[55]
Exchange Instructions
two way data transfer
XCH a, 30h ; a  M[30]
XCH a, R0 ; a  R0
XCH a, @R0 ; a  M[R0]
XCHD a, R0 ; exchange “digit”

a[7..4] a[3..0] R0[7..4] R0[3..0]

Only 4 bits exchanged


Data Processing Instructions

Arithmetic Instructions
Logic Instructions
Arithmetic Instructions
Add
Subtract
Increment
Decrement
Multiply
Divide
Decimal adjust
Arithmetic Instructions
ADD Instructions
add a, byte ; a  a + byte
addc a, byte ; a  a + byte + C

Subtract Instructions
Example:
SUBB A, #0x4F ;A  A – 4F – C

Notice that
There is no subtraction WITHOUT borrow.
Therefore, if a subtraction without borrow is desired,
it is necessary to clear the C flag.
Increment and Decrement

The increment and decrement instructions do NOT affect


the C flag.
Notice we can only INCREMENT the data pointer, not
decrement.
Multiply
When multiplying two 8-bit numbers, the size of the maximum product is
16-bits
FF x FF = FE01
(255 x 255 = 65025)
MUL AB ; BA  A * B
Note : B gets the High byte, A gets the Low byte
Division

Integer Division
DIV AB ; divide A by B

A  Quotient(A/B)
B  Remainder(A/B
Decimal Adjust
DA a ; decimal adjust a

Used to facilitate BCD addition.


Adds “6” to either high or low nibble after an addition
to create a valid BCD number.

Example:
mov a, #23h
mov b, #29h
add a, b ; a  23h + 29h = 4Ch (wanted 52)
DA a ; a  a + 6 = 52
Logic Instructions
 Bitwise logic operations
 (AND, OR, XOR, NOT)
 Clear
 Rotate
 Swap

Logic instructions do NOT affect the flags in PSW


Bitwise Logic
ANL  AND Examples:
00001111
ORL  OR ANL 10101100
XRL  XOR 00001100
CPL  Complement
00001111
ORL 10101100
10101111

00001111
XRL 10101100
10100011

CPL 10101100
Other Logic Instructions

CLR - clear
RL – rotate left
RLC – rotate left through Carry
RR – rotate right
RRC – rotate right through Carry
SWAP – swap accumulator nibbles
CLR ( Set all bits to 0)
CLR A
CLR byte (direct mode)
CLR Ri (register mode)
CLR @Ri (register indirect mode)
Rotate
Rotate instructions operate only on a

RL a

Mov a,#0xF0 ; a 11110000


RR a ; a 11100001

RR a

Mov a,#0xF0 ; a 11110000


RR a ; a 01111000
Program Flow Control

Unconditional jumps (“go to”)

Conditional jumps

Call and return


Unconditional Jumps
SJMP <rel addr> ; Short jump, relative address is 8-bit 2’s
complement number, so jump can be up to 127 locations forward, or
128 locations back.
LJMP <address 16> ; Long jump
AJMP <address 11> ; Absolute jump to anywhere within 2K block
of program memory
JMP @A + DPTR ; Long indexed jump
Conditional Jump
These instructions cause a jump to occur only if a
condition is true. Otherwise, program execution
continues with the next instruction.

loop: mov a, P1
jz loop ; if a=0, goto loop,
; else goto next instruction
mov b, a

There is no zero flag (z)


Content of A checked for zero on time
Conditional jumps
Call and Return
Call is similar to a jump, but
Call pushes PC on stack before branching

acall <address ll> ; stack  PC


; PC  address 11 bit

lcall <address 16> ; stack  PC


; PC  address 16 bit
Return
Return is also similar to a jump, but
Return instruction pops PC from stack to get address to
jump to

ret ; PC  stack
What is subroutines?

Subroutines allow us to have "structured"


assembly language programs.
This is useful for breaking a large design into
manageable parts.
It saves code space when subroutines can be
called many times in the same program.
Subroutines
Main: ...
acall sublabel call to the subroutine

...
...
sublabel: ...
...
ret
The subroutine
THANK YOU
y …
An
i f
i es
er
Qu

You might also like