Beruflich Dokumente
Kultur Dokumente
General-
Purpose Serial
RAM ROM I/O Timer
Micro- COM
Port
processor Port
Address Bus
CPU
Bus Serial
4 I/O Ports
OSC Control Port
P0 P1 P2 P3 TxD RxD
Address/Data
Pin description of 8051
P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0)
P1.2 3 38 P0.1(AD1)
P1.3
P1.4
4
5
8051 37
36
P0.2(AD2)
P0.3(AD3)
P1.5 6 (8031) 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 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)
Pin description of 8051
• Vcc(pin 40):
– Vcc provides supply voltage to the chip.
– The voltage source is +5V.
• GND(pin 20):ground
Pin description of 8051
• RST(pin 9):reset
– It is an input pin and is active high(normally low).
• The high pulse must be high at least 2 machine cycles.
– It is a 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
– Way 1:Power-on reset circuit
– Way 2:Power-on reset with debounce
Reset value of 8051
C2
XTAL2
30pF
C1
XTAL1
30pF
GND
Pin description of 8051
GND
Pins of I/O Port
D7 D6 D5 D4 D3 D2 D1 D0
MSB LSB
The most widely used registers
are A (accumulator), B, R0-R7,DPTR
(Data Pointer), PC (Program Counter). All
the registers except DPTR and the
program counter are 8 bits. DPTR and PC
are 16 bits.
Registers
A
R0
DPTR DPH DPL
R1
R2 PC PC
R3
R5
R6
R7
0001 1100
+0010 1111
0110 0111
30
2F
20
1F
18
17
10
0F
08
07
00
Register banks in 8051
32 bytes are set for register banks and
stack.32 bytes are divided into 4 banks of
registers in which each bank has 8
registers, R0-R7.
RAM location Register bank
00-07 0
08-0F 1
10-17 2
18-1F 3
Stack in 8051
• It is a section of RAM.
• Stack is used to store information
temporarily.
• The information could be data or address.
• CPU needs this storage area since there
are only a limited number of registers.
How stack is accessed?
• Since stack is a section of RAM, there must be
register inside the CPU to point to it.
• The register used to access the stack is called
Stack Pointer (SP).
• SP is 8 bits wide. It can take values 00-FFh.
• When powered up SP contains value 07.
• Storing of a CPU register in stack is called
PUSH and pulling the contents is called POP.
Addressing Modes
• The CPU can access data in various ways. The
data could be in a register or in memory or be
provided as an immediate value. These various
ways of accessing data are called addressing
modes.
• Total 5 addressing modes:
1)Immediate
2)Register
3)Direct
4)Register indirect
5)Indexed
Immediate addressing mode
• The source operand should be a constant.
• Immediate data must be preceded by the pound sign “#”.
• This mode can be used to load information into any of the registers,
including the DPTR register.
• Ex:
MOV A,#25h ;load 25h into A
• Although DPTR is 16 bit, it can be accessed as two 8-bit registers,
DPH and DPL.
• Ex:
MOV DPTR, #2550h
is same as,
MOV DPL, #50h
MOV DPH,#25h
Immediate addressing mode
• Value>65535(FFFFFh) is illegal, since it is
16-bit.
• This addressing mode can also be used to
send data to 8051 ports.
Register Addressing Modes
• Involves the use of registers to hold the data to be manipulated.
• Ex:
MOV A, R0 ;copy contents of R0 into A
• The source and destination registers must match in size.
• Ex:
MOV DPTR,A ;error
Because DPTR (Destination) is 16 bit and A (Source) is 8 bit.
• We can move data between Accumulator and Rn (for n=0 to7), but
movement of data between Rn is not allowed.
• Ex:
MOV R4,R7 ;Invalid
Register Addressing Modes
• In the above 2 addressing modes, the operands
are either inside one of the registers or tagged
along with the instruction itself.
• But in most programs, data to be processed is
often in some memory location of RAM or in the
code space of ROM. The ways to access these
data are:-
• Direct, Register Indirect, Indexed
• Inorder to access data stored in RAM or register
of 8051, we can use Direct or Register indirect.
Direct addressing Mode
• Entire RAM (128bytes) can be accessed using this addressing
mode.
• It is most often used to access RAM location 30-7Fh.
• This is because register bank location are accessed by the register
names of R0-R7, but there is no such name for other RAM locations.
• The ‘#’ symbol distinguishes between the direct addressing and
immediate addressing mode.
• In this addressing mode, the data is in a RAM memory location
whose address is known, and this address is given as part of
instruction.
• Ex:
MOV R0,40h ;save the contents of RAM location 40h in R0
MOV 56h,A ;save the contents of A in RAM location 56h.
Direct addressing Mode
• RAM locations 0 to 7 are allocated to bank 0 registers R0-R7. These
registers can be accessed in 2 ways.
• Ex:
MOV A,4 ;is same as
MOV A,R4 ;which means copy R4 into A
Register Indirect addressing Mode
• Here register is used as a pointer to the data.
• If the data is inside CPU, only registers R0 and
R1 are used for this purpose.
• When R0 and R1 are used as pointers, i.e.,
when they hold the address of RAM, they must
be preceded by “@” sign.
• Ex:
MOV A,@R0 ;move contents of RAM location whose address is
;held by R0 into A.
Register Indirect addressing Mode
MOV @R1,B ;move contents of B into RAM location whose address is held
;by R1.
• 8-bit datatype.
• value range from 0-255(00-FFh).
Signed char
• 8-bit datatype.
• D7 of D7-D0 represent sign(-ve or +ve).
• We have 7 bits for value of signed number.
• Range from -128 to 127.
• Default is signed value.
Unsigned int
• 16bit datatype.
• value in a range of 0-65535.
• used to define 16-bit memory address.
• 8051 is 8-bit microcontroller, so int datatype take
2bytes of RAM.
Signed int
• 16 bit datatype.
• Uses MSB (D15 of D15-D0) to represent
sign(-ve or +ve).
• 15 bit for magnitude.
• Value range from -32768 to 32767.
sbit (single bit)
• Keyword used to access single bit addressable
registers.
• Allows access to the single bits of the SFR
registers.
bit and sfr
• bit datatype allows to access single bit of bit
addressable memory space of RAM 20-2Fh.
• sfr is used to access byte size SFR registers i.e.,
memory space 80-FFh.
Time Delay
There are two ways to create a
time delay 8051:
Parallel
Serial
• In parallel data transfer, often 8 or more lines (wire
conductors) are used to transfer data to a that is only a
few feet away.