Page 1
Port 3: Port 3 is an 8-bit bi-directional I/O port with internal pull-ups. All the P3
pins have alternate functions as shown in the following table-
Port Pin
P3.0
P3.1
P3.2
P3.3
P3.4
P3.5
P3.6
P3.7
Alternate Functions
RXD (serial input port)
TXD (serial output port)
INT0 (external interrupt 0)
INT1 (external interrupt 1)
T0 (timer 0 external input)
T1 (timer 1 external input)
WR (external data memory write strobe)
RD (external data memory read strobe)
PSEN: Program Store Enable (PSEN) is the read strobe to external program
memory. While executing code from external program memory, PSEN is
activated twice each machine cycle.
Page 2
Address Map:
For memory 89C51 can use both internal or/and external memory. Internally it
can address 4KB program memory (ROM) and 128B (in some variant 256B) data
Page 3
memory (RAM) space. However it can address 64KB of memory (ROM or/and
RAM) using the external address and data buses like the 8085 does.
Program Memory: The memory space, where the program (instructions with
required constants) are stored. It is in general the ROM. For 8051, internal 4KB
can be used with external 60KB memory or only 64KB external memory should
be used.
Data Memory: The memory space, where the variable data (required for the
program) are stored or to be stored. It is in general the RAM. 8051 data memory
consists of internal 128B RAM and external 64KB Memory. Internal 256B
address spaces are allocated to the registers, bit-addressable block and RAM.
Page 4
SFR:
Type
Reg
System
Data
Control
Power
Reg. Array
Parallel
Port
UART
Timer
Config.
T/C 0
T/C 1
Interrupt
Register
A (ACC)
B
PC
SP
PSW
DPL
DPH
PCON
R0-R7
R8-R15
R16-R23
R24-R31
P0
P1
P2
P3
SCON
SBUF
TMOD
TCON
TH0-TL0
TH1-TL1
IP
IE
Length
8
8
16
8
8
8
8
8
8x8
8x8
8x8
8x8
8
8
8
8
8
8
8
8
16
16
8
8
Address
E0
F0
81
D0
82
83
87
00-07
08-0F
10-17
18-1F
80
90
A0
B0
98
99
89
88
8C-8A
8D-8B
B8
A8
Ini-value
00
00
0000
07
00
00
00
00
00
00
00
00
FF
FF
FF
FF
00
00
00
00
00
00
00
00
Bit-addressable.
Page 5
8051 Programming
Data Type:
Decimal:
Hex:
Binary:
ASCII Number:
ASCII Character:
28
28H
00011100B
28
Twenty Eight
Page 6
Instruction Set:
8051 instructions are divided into 5 typesArithmetic
ADD
ADD
ADD
ADD
Logical
A,Rn
A,addr8
A,@Ri
A,#data8
ANL A,Rn
ANL A,addr8
ANL A,@Ri
ANL A,#data8
ANL addr8,A
ADDC A,Rn
ANL addr8,#data8
ADDC A,addr8 ORL A,Rn
ADDC A,@Ri
ORL A,addr8
ADDC A,#data8 ORL A,@Ri
ORL A,#data8
SUBB A,Rn
SUBB A,addr8 ORL addr8,A
ORL addr8,#data8
SUBB A,@Ri
SUBB A,#data8 XRL A,Rn
XRL A,addr8
INC A
XRL A,@Ri
INC Rn
XRL A,#data8
INC addr8
XRL addr8,A
INC @Ri
XRL addr8,#data8
INC DPTR
CLR A
DEC A
CPL A
DEC Rn
RL A
DEC addr8
RLC A
DEC @Ri
RR A
MUL AB
RRC A
DIV AB
SWAP A
DA A
Boolean
CLR C
CLR bit
SETB C
SETB bit
CPL C
CPL bit
ANL C,bit
ANL C,/bit
ORL C,bit
ORL C,/bit
MOV C,bit
MOV bit,C
JC rel8
JNC rel8
JB bit,rel8
JNB bit,rel8
JBC bit,rel8
Data Transfer
Branching
MOV A,Rn
ACALL addr11
MOV A,addr8
LCALL addr16
MOV A,@Ri
RET
MOV A,#data8
RETI
MOV Rn,A
MOV Rn,addr8
AJMP addr11
MOV Rn,#data8
LJMP addr16
MOV addr8,A
SJMP rel8
MOV addr8,Rn
JMP @A+DPTR
MOV addr8,addr8
JZ rel8
MOV addr8,@Ri
JNZ rel8
MOV addr8,#data8
MOV @Ri,A
CJNE A,addr8,rel8
MOV @Ri,addr8
CJNE A,#data8,rel8
MOV @Ri,#data8
CJNE Rn,#data8,rel8
MOV DPTR,#data16
CJNE @Ri,#data8,rel8
MOVC A,@A+DPTR
MOVC A,@A+PC
DJNZ Rn,rel8
MOVX A,@Ri
DJNZ addr8,rel8
MOVX A,@DPTR
NOP
MOVX @Ri,A
MOVX @DPTR,A
PUSH addr8
POP addr8
XCH A,Rn
XCH A,addr8
XCH A,@Ri
XCHD A,@Ri
Rn = R0 - R7,
@Ri = @R0 or @R1,
rel8 = -128 - +127,
bit = 0 - 255
Addressing:
The 8051 offers the following addressing modes:
Page 7
Immediate Addressing:
MOV A,#data8
addr8,#data8
MOV Rn,#data8
MOV DPTR,#data16
MOV
MOV A,#5 ; load the ACC with the value 5, # stands for value
Register Addressing:
It specifies one of the 8 available registers R0 through R7 as the source. An
example of register addressing is:
MOV A, Rn
MOV Rn, A
MOV Rn,addr8
MOV addr8,Rn
MOV A,@R0
MOV addr8,@Ri
MOV @Ri,addr8
MOV @Ri,#data8
Page 8
Branching:
8051 has 3 different types of branching1. Relative or Short
2. Long
3. Absolute
1. Relative or Short branching: All conditional jumps are relative
branching to +127 or -127 from the next instruction address of the jump
instruction
2. Long branching: It can branch anywhere within the 16-bit address
space (64KB) by the LJMP and LCALL instruction
3. Absolute branching: It can branch anywhere within the 11-bit address
space (2KB) by the ACALL instruction
Interrupts
The 8051 can respond to three different interrupts which are:
Interrupt Vector:
Interrupt
Reset
interrupt #0
timer #0 overflow
interrupt #1
timer #1 overflow
serial port
Address
0000
0003
000B
0013
001B
0023
Priority
0
1
2
3
4
5
Page 9
D7
EA
Global
IE
D6
-
Interrupt
Priority
Register
(IP)
D5
-
D4
D3
D2
D1
ES
ET1
EX1
ET0
Serial
Timer- Ext Int- TimerInt
1
1
0
1= Enable, 0=Disable
ES
ET1
EX1
ET0
Serial
Timer- Ext Int- TimerInt
1
1
0
1= Increase priority, 0= Default priority
D0
EX0
Ext
Int-0
PX0
Ext
Int-0
Page 10