What Is Microcontroller?
What Is Microcontroller?
What Is Microcontroller?
What is Microcontroller?
What is Microcontroller?
What is Microcontroller?
Inside a Microcontroller
Uses of Microcontrollers
History of Microcontrollers
Other Microcontrollers
Microcontroller and
Microprocessor
Microprocessor and
Microcontroller
Difference Continued
Von Neumann
architecture
Harvard architecture
Harvard architecture
CISC Architecture
CISC Architecture
RISC Architecture
Introduction to 8051
8051 Features
Differences in
microcontrollers
1
2
3
4
5
6
7
8
9
1
1
0
1
1
2
3
1
1
4
1
5
1
6
7
1
1
8
2
9
0
8051
(8031
)
4
3
0
3
9
8
3
3
7
3
6
5
3
3
4
3
3
2
3
1
2
0
2
9
8
2
2
7
2
6
2
5
2
4
2
3
2
1
Vcc
P0.0(A
P0.1(AD1)
D0)
P0.2(A
P0.3(AD
D2)
3)
P0.4(AD
P0.5(AD5
4)
)P0.6(AD6)
P0.7(AD
7)
EA/VPP
ALE/PRO
G
PSEN
P2.7(A15)
P2.6(A1
P2.5(A1
4)
P2.4(A1
3)
P2.3(A1
2)
P2.2(A1
1)
P2.1(A9
0)
)P2.0(A8
)
8051 Pins
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
8051 Pins
8051 Pins
Port 3
P3 Bit
Function
Pin
P3.0
RxD
10
P3.1
TxD
11
P3.2
INT0
12
P3.3
INT1
13
P3.4
T0
14
P3.5
T1
15
P3.6
WR
16
P3.7
RD
17
The CPU
CPU - Basics
CPU - Working
CPU - Working
CPU - Basics
CPU - Basics
CPU - Basics
CPU - Basics
CPU - Working
Types of Memory
Types of Memory
Types of Memory
Code Memory
Types of Memory
External RAM
Types of Memory
On-chip memory
Register Banks
Register Banks
ADD A,R4
ADD A,04h
This instruction adds the value found in Internal RAM address 04h to
the value of the Accumulator, leaving the result in the Accumulator.
Since R4 is really Internal RAM 04h, the above instruction effectively
accomplished the same thing.
Bit Memory
SFR Descriptions
SFR Description
SFR Description
SFR Description
SFR Description
SFR Description
SFR Description
SFR Description
SFR Description
SFR Description
SFR Description
SFR Description
SFR Description
SFR Description
SFR Description
SFR Description
SFR Description
SFR Description
Addressing Modes.
Immediate
Register
Direct
Register Indirect
Indexed
Addressing Modes.
Immediate Addressing
MOV A,#20h
This instruction uses Immediate Addressing because the
Accumulator will be loaded with the value that
immediately follows; in this case 20 (hexidecimal).
Addressing Modes.
MOV A,R0
MOV R2,A
Addressing Modes.
Direct Addressing
MOV A,30h
This instruction will read the data out of Internal RAM
address 30 (hexidecimal) and store it in the Accumulator.
Addressing Modes.
Indirect Addressing
MOV A,@R0
This instruction causes the 8051 to analyze the value of the R0
register. The 8051 will then load the accumulator with the value from
Internal RAM which is found at the address indicated by R0.
For example, lets say R0 holds the value 40h and Internal RAM
address 40h holds the value 67h. When the above instruction is
executed the 8051 will check the value of R0. Since R0 holds
40h the 8051 will get the value out of Internal RAM address 40h
(which holds 67h) and store it in the Accumulator. Thus, the
Accumulator ends up holding 67h.
Indirect addressing always refers to Internal RAM; it never refers
to an SFR.
Addressing Modes.
Registers
A
B
R0
DPTR
DPH
DPL
R1
R2
PC
PC
R3
R4
R5
R6
R7
Some 8-bitt Registers of
the 8051
Programming
Microcontrollers
Why Assembly ?
What is a Assembly
Language ?
Integrated Development
Environment (IDE)
IDE
IDE
IDE
IDE
Keil uVision
Assembly Instructions
Opcode
Operand
Types of Instructions
Arithmetic Instructions
Branch Instructions
Data Transfer Instructions
Logic Instructions
Bit-oriented Instructions
PSW Register
PSW Register
PSW Register
PSW Register
8051 Directives
ORG (origin)
The ORG directive is used to indicate the
beginning of the address. The number that
comes after ORG can be either in hex or in
decimal. If the number is not followed by H,
it is decimal and the assembler will convert
it to hex. Some assemblers use ". ORG"
(notice the dot) instead of "ORG" for the
origin directive. Check your assembler.
E.g. ORG 500H
8051 Directives
END directive
Another important pseudocode is the END
directive. This indicates to the assembler the
end of the source (asm) file. The END directive
is the last line of an 8051 program, meaning
that in the source code anything after the END
directive is ignored by the assembler. Some
assemblers use ". END" (notice the dot) instead
of "END".
8051 Directives
EQU (equate)
This is used to define a constant without
occupying a memory location. The EQU
directive does not set aside storage for a data
item but associates a constant value with a
data label so that when the label appears in
the program, itp constant value will be
substituted for the label. The following uses
EQU for the counter constant and then the
constant is used to load the R3 register.
8051 Directives
DB (define byte)
8051 Directives
Label Rules
DJNZ
Operation:DJNZ
Function:Decre
ment and Jump
if Not Zero
Syntax:DJNZ
register,reladdr
DJNZ
DJNZ example
JZ
Operation:JZ
Function:Jump if
Accumulator Zero
Syntax:JNZ
reladdr
JNZ
Operation:JNZ
Function:Jump if
Accumulator Not
Zero
Syntax:JNZ
reladdr
CJNE
Operation:CJNE
Function:Compar
e and Jump If Not
Equal
Syntax:CJNE
operand1,operand
2,reladdr
CJNE
CJNE
REPEAT:
MOV A,TH0
MOV R0,TL0
CJNE A,TH0,REPEAT
JC
Operation:JC
Function:Jump if
Carry Set
Syntax:JC reladdr
JC will branch to the
address indicated by
reladdr if the Carry Bit
is set.
If the Carry Bit is not
set program execution
continues with the
instruction following
the JC instruction.
JC
JC example
MOV C,P1.4
JC LINE1
JNC
Operation:JNC
Function:Jump if
Carry Not Set
Syntax:JNC reladdr
JNC branches to the
address indicated by
reladdr if the carry bit
is not set.
If the carry bit is set
program execution
continues with the
instruction following
the JNB instruction.
JNC example
JNC example
MOV C,P1.4
JNC LINE1
JB
Operation:JB
Function:Jump if Bit Set
Syntax:JB bit addr, reladdr
JB branches to the address
indicated by reladdr if the
bit indicated by bit addr is
set.
If the bit is not set program
execution continues with
the instruction following
the JB instruction.
JB 45h,LABEL1
JNB
Operation:JNB
Function:Jump if Bit Not
Set
Syntax:JNB bit
addr,reladdr
JNB will branch to the
address indicated by
reladdress if the indicated
bit is not set.
If the bit is set program
execution continues with
the instruction following
the JNB instruction.
JNB 45h,LABEL1
JBC
Operation:JBC
Function:Jump if Bit Set and
Clear Bit
Syntax:JBC bit addr, reladdr
JBC will branch to the
address indicated by reladdr
if the bit indicated by bit
addr is set. Before branching
to reladdr the instruction will
clear the indicated bit.
If the bit is not set program
execution continues with the
instruction following the JBC
instruction.
JBC 45h, LABEL1
Jump if A=0
JNZ
Jump if A/=0
DJNZ
CJNE A,byte
Jump if A/=byte
CJNE reg,#data
Jump if byte/=#data
JC
Jump if CY=1
JNC
Jump if CY=0
JB
Jump if bit=1
JNB
Jump if bit=0
JBC