Professional Documents
Culture Documents
MICROPROCESSORS
&
MICROCONTROLLER
EC-602
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
LESSON PLAN
Module-2
8051 architecture:
8051 micro controller hardware, input/output pins, ports, external
memory, counters and timers, instruction set, addressing modes,
serial data i/o, interrupts.
LESSON PLAN
Module-2
Assembly language Programming:
Logical operations:
Byte-level, bit-level, rotate and swap operations.
Arithmetic operations:
Flags, incrementing and decrementing, addition, subtraction,
multiplication and division, decimal
arithmetic.
Jump and call instructions:
Jump and call program range, jumps, calls and subroutines, interrupts
and returns.
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
THE 8051
MICROCONTROLLER
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
What is a microcontroller ?
Basically a device which integrates a number of components of a
microprocessor system on to a single chip, only need to supplied
power and clocking.
6
7
BLOCK DIAGRAM
External Interrupts
CPU
OSC Bus
4 I/O Ports Serial
Control
P0 P2 P1 P3 TXD RXD
Addr/Data
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
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
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
ARCHITECTURE
OF
8051
PIN DIAGRAM
P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0
P1.2 3 38 )P0.1(AD1)
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 33 P0.6(AD6)
RST 9 32 P0.7(AD7)
(RXD)P3.0 10 8051 31 EA
(TXD)P3.1 11 30 ALE
(INT0)P3.2 12 MC 29 PSEN
(INT1)P3.3 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)
13
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
PIN DISCRIPTION
One of the most useful features of the 8051 is that it contains four I/O ports
(P0 - P3)
PIN DISCRIPTION
Vcc ( pin 40 ): Vcc provides supply voltage to the chip. The
voltage source is +5V.
GND ( pin 20 ): Ground.
XTAL1 and XTAL2 ( pins 19,18 ): These 2 pins provide
external
clock by using a quartz crystal oscillator.
C2
XTAL2
30pF Using a quartz crystal oscillator
C1 We can observe the frequency
XTAL1 on the XTAL2 pin.
30pF
GND
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
PIN DISCRIPTION
Vcc ( pin 40 ): Vcc provides supply voltage to the chip. The
voltage source is +5V.
GND ( pin 20 ): Ground.
XTAL1 and XTAL2 ( pins 19,18 ): These 2 pins provide
external
clock by using a quartz crystal oscillator.
C2
XTAL2
30pF Using a quartz crystal oscillator
C1 We can observe the frequency
XTAL1 on the XTAL2 pin.
30pF
GND
PIN DISCRIPTION
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.
Reset values of some 8051 registers power-on reset circuit
Register Reset Value
PC 0000
ACC 0000
B 0000
PSW 0000
SP 0007
DPTR 0000
RAM are all zero
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
8051 MEMORY
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
WR
RD
PSEN OE
ALE 74LS373 CS
G
P0.0 A0
D
P0.7 A7
D0
D7
EA
P2.0 A8
P2.7 A15
8051 ROM
TIMMING DIAGRAM
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
Interface to 1K RAM
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
D0
D7
EA
P2.0 A8
P2.7 A15
RAM
Interfaceing to RAM
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
ARCHITECTURE
OF
8051
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
ARCHITECTURE OF 8051
Accumulator : It is an 8 – bit register used for
arithmetic and logical operation to
accumulate the result.
Several function like rotate, swap etc
apply on the accumulator
ARCHITECTURE OF 8051
ALU : The ALU can perform arithmetic and logical
operation on 8-bit data. Like add, sub, mul, div
or AND or OR ,compliment, etc.
ARCHITECTURE OF 8051
DPTR: DATA POINTER
The data pointer is 16 bit register
It is used to hold the address of data in the memory.
It can be accessed separately as lower 8 bit (DPL) and
higher 8 bit (DPH)
The DPTR does not have a single internal address
instead DPH and DPL are each assigned a separate
address.
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
ARCHITECTURE OF 8051
STACK AND STACK POINTER
The stack is the reserved area of the memory in the
RAM where temporary information may be stored.
An 8 – bit stack pointer is used to hold the address of
most recent stack entry. Generally it is called top of the
stack.
It work on LIFO or FILO principle.
By default location of stack pointer is 07h
we can change the default location by MOV SP,# XX h
( RAM location 30h – 7Fh)
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
ARCHITECTURE OF 8051
STACK IN THE 8051
7FH
The register used to access the
Scratch pad RAM
stack is called SP (stack pointer)
register. 30H
2FH
Bit-Addressable RAM
The stack pointer in the 8051 is
20H
only 8 bits wide, which means that 1FH Register Bank 3
it can take value 00 to FFH. 18H
17H
Register Bank 2
10H
When 8051 powered up, the SP 0FH (Stack) Register Bank 1
register contains value 07. 08H
07H
Register Bank 0
00H
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
ARCHITECTURE
OF
8051
MEMORY ORGANIZATION
8051 MEMORY
FFFF FFFF FFFF
up to 60 KB SF = Special Function
of external
ROM/
EPROM
up to 64
KB of 00F8 up to 64 KB
external 1000 of external
EPROM/ 21 SF registers RAM
ROM or and 0080
0FFF 007F
128 KB internal
4 KB of RAM
internal
ROM/
EPROM
0000 0000 0000
0000
Bit addressable
RAM 16 bytes ( 80
0F 0E 0D 0C 0B 0A 09 08 bits)
2 07 06 05 04 02 00
0 03 01
1F Bank 4 Reg. BANK
3 8 bytes each
Bank Total 32 bytes
0 2
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
30H
2FH
Bit-Addressable RAM
20H
1FH
18H Register Bank 3
17H
10H Register Bank 2
0FH
08H Register Bank 1
07H
00H Register Bank 0
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
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 R4 Bank 0
03 R3
02 R2
01 R1
00 R0
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
DATA registers
CONTROL registers
Timers
Serial ports
Interrupt system Addresses 80h – FFh
Analog to Digital converter
Digital to Analog converter Direct Addressing used to
access SPRs
Etc.
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
ARCHITECTURE
OF
8051
ADDRESSING MODES
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
ADDRESSING MODES
• Immediate
• Register
• Direct
• Register Indirect
• Indexed
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
Note:
Because the STATIC data elements are stored in the program (code )
space ROM of the 8051, it uses the instruction MOVC instead of MOV. The
“C” means code.
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
ARCHITECTURE
OF
8051
INSTRUCTION SETS
ARITHMETIC
INSTRUCTION
OF
8051
SUBTRACT
SUBB A, byte subtract with borrow
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.
Example:
Clr c
SUBB A, #4F ;A A – 4F
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
69
DIVISION
• Integer Division
DIV AB ; divide A by B
A Quotient(A/B)
B Remainder(A/B)
RL a
Mov a,#0xF0 ; a 11110000
RR a ; a 11100001
RR a
Mov a,#0xF0 ; a 11110000
RR a ; a 01111000
74
ROTATE THROUGH CARRY
C
RRC a
mov a, #0A9h ; a A9
add a, #14h ; a BD (10111101), C0
rrc a ; a 01011110, C1
C
RLC a
SWAP a
76
BIT CLR
Mnemonic
C Clear C
Description
INSTRUCTION CLR
SETB C
bit Clear direct bit
Set C
CPL C Complement c
8051 CPL bit Complement direct bit
LJMP addr16
Absolute jump
Long jump
CJNE A,direct,rel
CJNE A,#data,rel
Compare and Jump if Not Equal
CJNE Rn,#data,rel
CJNE @Ri,#data,rel
DJNZ Rn,rel
Decrement and Jump if Not
Zero
DJNZ direct,rel
NOP No Operation
UNIVERSITY
OF ENGINEERING & MANAGEMENT, KOLKATA
THANK YOU