Professional Documents
Culture Documents
CPU
RAM
ROM
I/O
Port
Timer
Serial
COM
Port
RAM
ROM
I / O Timer
Serial
COM
Port
Address bus
(a) General-purpose Microprocessor System
(b) Microcontroller
Power consumption
Amount of RAM and ROM on chip
No. of I/O pins and timers on chip
Cost
INTERRUPT
CONTROL
ON-CHIP
ROM
for
program
code
ON-CHIP
RAM
ETC.
TIMER 0
TIMER 1
T1
T0
COUNTER INPUTS
INT1
INT0
CPU
30PF
4I/O
PORTS
BUS
CONTROL
OSC
30PF
4 to 30 MHz
normally 11.0592 MHz
P0 P1 P2 P3
SERIAL
PORT
TXD
RXD
ADDRESS / DATA
banks and stack. But other 128 byte RAM which consists of SFRs. We will
discuss the RAM in detail in next section.
Now what is the meaning of 128 byte RAM. What are address range which
is provided for data storage. We will discuss here.
We know that 128 byte = 27 byte
7
if initial address is
(00H)
(7FH)
Since 27 bytes so last 7 bits can be changed so total locations are from 00H
to 7F H. This procedure of calculating the memory address is called as memory
mapping. We can save data on memory locations from 00H to 7FH. Means total
128 byte space from 00H to 7FH is provided for data storage.
1.4.2 4KB ROM
In 8051, 4KB read only memory (ROM) is available for program storage.
This is used for permanent data storage. Or the data which is not changed
during the processing like the program or algorithm for specific applications.
This is volatile memory; the data saved in this memory does not disappear
after power failure.
We can interface up to 64KB ROM memory externally if the application is
large. These sizes are specified different by their companies.
Address Range of PC: Address range of PC means program counter (which
points the next instruction to be executing) can be moved between these
locations or we can save the program from this location to this location.
The address range can be calculated in the same way just like the RAM
which is discussed in previous section.
4KB = 2 2 210 B (since 1KB = 210 B)
= 212 Byte
Address range of PC is 0000H to 0FFFH means total 4KB locations are available
from 0000H to 0FFFH. At which we can save the program.
If we want to load T0 with 16 bit data then we can load separate lower 8 bit
in TL0 and higher 8 bit in TH0.
In the same way for T1.
TMOD, TCON registers are used for controlling timer operation.
1.4.4 Serial Port
There are two pins available for serial communication TXD and RXD.
Normally TXD is used for transmitting serial data which is in SBUF register,
RXD is used for receiving the serial data.
SCON register is used for controlling the operation.
There are four modes of serial communication which has been discussed in
next chapter.
P1.0
P1.1
P1.2
P1.3
40
V cc
39
P0.0 (AD0)
38
P0.1 (AD1)
37
P0.2 (AD2)
P1.4
8051
36
P0.3 (AD3)
P1.5
P0.4 (AD4)
P1.6
(8031)
(89420)
35
34
P0.5 (AD5)
P0.6 (AD6)
P0.7 (AD7)
P1.18
P1.7
RST
33
32
(RXD) P3.0
10
31
EA / VPP
(TXD) P3.1
11
30
ALE / PROG
(INT0) P3.2
12
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)
EA
XTAL 1
XTAL 2
RESET
Vcc
GND
Port 0
Port 1
I/O
A15A8
ROM
ALE
PSEN
Port 2
DPTR
DPH
DPL
I/O
System
Timing
System
Interrupts
Timers
Data Buffers
Memory Control
Byte/Bit
Addresses
Special
Function
Register
Register
Bank 3
IE
IP
Register
Bank 2
Register
Bank 1
Register
Bank 0
Port 3
PC
Latch
I/O
AD7AD0
Latch
Special
Function
Registers
RAM
PSW
Latch
Arithmetic
and
Logic Unit
Latch
PCON
SBUF
SCON
TCON
TMOD
TL0
TH0
TL1
TH1
I/O
Interrupt (INT0,9 INT1)
Counter (T0,9T1)
Serial Data
(TXD, RXD)
RD, WR
0 00 0
1 11 1
00 0 0
11 1 1
0 00 0
1 11 1
0000
1111
(0000H)
(F F F F H)
PC
Mnemonics
Machine codes
MOV R5, #25H
7D 25
MOV A, #00H
74 00
ADD A, R5
2D
HERE: SJMP HERE; 80 FE
When 7D is accessed then PC locate the
0001H (next instruction to be executed)
When 00 is accessed then PC locate the
0004H (next instruction to be executed)
7D
0000H
25
0001H
74
0002H
00
0003H
2D
0004H
80
0005H
FE
0006H
10
00 0 0
00 0 0
00 0 0
11 1 1
00 00
11 11
0 0 00
1 1 11
(Starting Address)
(Max Address)
PSW0.6
PSW0.5
CY
AC
F0
PSW0.4
RS1
PSW0.3
PSW0.2
PSW0.1
PSW0.0
RS0
OV
FLAG Register
RS1(PSW0.4)
RS0(PSW0.3)
Register Bank Select
0
0
Bank 0
0
1
Bank 1
1
0
Bank 2
1
1
Bank 3
for selecting Bank 1, we use following commands
SETB PSW0.3 (means RS0=1)
CLR PSW0.4 (means RS1=0)
Initially by default always Bank 0 is selected.
F0 user definable bit
AC Auxiliary carry flag when carry is generated from D3 to D4, it
is set to 1, it is used in BCD arithmetic.
1
0 0 0 0
+ 0 1 0 1
1
1 1 1 0
1 0 1 0
(0EH)
(5AH)
0 1 1 0
1 0 0 0
(38H)
11
(00H)
(7FH)
09
00
01
20H
1FH
R7
18H
17H
R0
R7
10H
0FH
R0
R7
08H
07H
R0
R7
00H
R0
02
03
04
05
06
07
Bank 3
Stack
Bank 2
Bank 1
Bank 0
SP = 07 (initially)
12
2
0
R0
PUSH 06
PUSH 014
13
POP 04
0B
0A
R4 = 124
12(R1)
09
08
initially
SP = 074
25(R6)
25(R6)
SP = 084
SP = 09
25
if we want to use more than 24byte (08H to 1FH) of stack. We can change
SP to point RAM address 30H to 7FH by MOV SP,
#XX
Any value from 30 to 7FH
1.6.8.1 Conflicting of Register Banks and Stack
We know locations from 08H to 1FH is used as stack and it is also used as
register bank.
If in the program, we use the Register Bank 1 to 3 and also use the stack
then conflicts exist and error can be possible.
For removing this situation we use the stack from location 30H to 7FH by
shifting SP to 2FH.
MOV SP,#2FH;
1.6.9 DPTR Data Pointer in 8051
16 bit register, it is divided into two parts DPH and DPL.
DPH for Higher order 8 bits, DPL for lower order 8 bits.
DPTR, DPH, DPL these all are SFRs in 8051.
1.6.10 Special Function Register
(See Fig.) RAM scratch pad, there is extra 128 byte RAM which is used to
store the SFRs
Following figure shows special function bit address, all access to the four
I/O ports CPU register, interrupt control register, timer/counter, UART,
power control are performed through registers between 80H and FFH.
14
15
LINKER
PROGRAM
myfile.abs
OH
PROGRAM
myfile.hex
Steps:
Type your program in editor of software widely used editors are notepad.
Save this file with
file name . asm } depending on assembler
or
file name . src
notepad produce ASCII file.
16
ASM source file contains program code assembler converts the instruction
into machine code and produces obj file and 1st file (object file and
link file).
Linker program takes one or more object files and produces an absolute
object file with extension abs.
abs file is used by 8051 trainer that have a monitor program.
abs file is fed into a program code called OH (object to Hex converter).
Which create a file with extension Hex that is ready to burn into ROM
lst file contains all opcode and address as well as error that assembler
detected.
REVIEW QUESTIONS
1. Differentiate between microprocessor and microcontroller. Draw and explain
the block diagram of 8051. (RTU-EC-2010)
2. What do you mean by memory map? How the address range of ROM is
defined? Write the address range for following memory:
(a) 8KB ROM
(b) 64 KB ROM
3. Differentiate between RAM and ROM. Draw the structure of RAM in 8051.
If we want to use the stack from location 30H to 7FH then what is the
procedure for it?
4. What do you mean by bit addressability and byte addressability? Explain
with the help of example. What is the procedure for eliminating the conflict
of register bank and stack?
5. Why is the coding done in assembly language instead of being written in
machine codes directly by programmer? What are different components in
instruction? (RTU-EC-2010)
6. What are the different ways of classifying the types of microcontroller and
list the alternate uses of each pin available in 8051 when used in expanded
mode? (RTU-EC-2010)
7. What are the pointers in 8051? Explain the use of each pointer. Explain the
stack feature in 8051. (RTU-EC-2010)
8. How the P0 and P2 are used for data bus and address bus and also used as
Input Output Port?
9. What is the difference of stack according to operation in 8051, 8085?
10. Differentiate PSW in 8051 and 8085 also write difference between carry
flag and OV flag.
11. Explain the use of SFR available in 8051 also write different types of SFR.
12. What are the registers available in 8051? What are the functions of 8051
registers?
13. What is a memory map? Why is it needed?