Académique Documents
Professionnel Documents
Culture Documents
FEATURES:
BLOCK DIAGRAM:
External
Interrupts
ETC.
Counter Inputs
On-chip
ROM for Timer 0
Interrupt
program On-chip
control
code RAM Timer 1
CPU
Osc
Bus Serial
4 I/O Ports
control port
P0 P1 P2 P3 TXD RXD
ADDRESS/DATA
PIN CONFIGURATIONS:
P1.0 Vcc
1 40
P1.1 P0.0 (AD0)
2 39
P1.2 P0.1 (AD1)
3 38
P1.3 P0.2 (AD2)
4 37
P1.4 P0.3 (AD3)
5 36
P1.5 P0.4 (AD4)
6 35
P1.6 P0.5 (AD5)
7 34
P1.7 8 33 P0.6 (AD6)
(T0) P3.4 14 27
P2.6 (A14)
(T1) P3.5 15 26
P2.5 (A13)
PIN DESCRIPTION:
16 25
(WR) P3.6 P2.4 (A12)
17 24
(RD) P3.7 P2.3 (A11)
GND - Ground.
Port 0 - Port 0 is an 8-bit open-drain bi-directional I/O port. As an
output port, each pin can sink eight TTL inputs. When 1s are written
to port 0 pins, the pins can be used as high-impedance inputs.
Port 0 also receives the code bytes during Flash programming, and
outputs the code bytes during program verification. External pull-ups
are required during program verification.
When 1s are written to Port 2 pins they are pulled high by the internal
pull-ups and can be used as inputs. As inputs, Port 2 pins that are
externally being pulled low will source current (IIL) because of the
internal pull-ups. Port 2 emits the high-order address byte during
fetches from external program memory and during accesses to
external data memory that use 16-bit addresses (MOVX @ DPTR). In
this application, it uses strong internal pull-ups when emitting 1s.
During accesses to external data memory that use 8-bit addresses
(MOVX @ RI), Port 2 emits the contents of the P2 Special Function
Register.
Port 2 also receives the high-order address bits and some control
signals during Flash programming and verification.
Port 3 - Port 3 is an 8-bit bi-directional I/O port with internal pullups.
The Port 3 output buffers can sink/source four TTL inputs. When 1s
are written to Port 3 pins they are pulled high by the internal pullups
and can be used as inputs. As inputs, Port 3 pins that are externally
being pulled low will source current (IIL) because of the pullups. Port
3 also serves the functions of various special features of the
AT89C51 as listed below:
RST - Reset input. A high on this pin for two machine cycles while the
oscillator is running resets the device.
ALE/PROG - Address Latch Enable output pulse for latching the low
byte of the address during accesses to external memory. This pin is
also the program pulse input (PROG) during Flash programming.
This pin also receives the 12-volt programming enable voltage (VPP)
during Flash programming, for parts that require 12-volt VPP.
XTAL2
C2
GND
D7 D6 D5 D4 D3 D2 D1 D0
PROGRAM COUNTER:
The PSW contains status bits that reflect the current state of the CPU
and is also called flag register. The PSW contains the Carry bit, the
Auxiliary Carry bit, the two register bank select bits, the overflow flag
bit, a parity bit, and two user definable status flags.
This flag is set whenever there is a carry out from the D7 bit. This flag
bit is affected after an 8-bit addition or subtraction. It can also be set
to 1 or 0 directly by an instruction such as “SETB C” and “CLR C”
where “SETB C” stands for “set bit carry” and “CLR C” for “clear
carry”.
There are 128 bytes of RAM in the 8051, which are assigned
addresses 00 to 7FH. These 128 bytes are divided into three different
groups:
2. A total of 16 bytes from locations 20H to 2FH are set aside for
bit-addressable read/write memory.
3. A total of 80 bytes from locations 30H to 7FH are used for read
and write storage, or what is normally called a scratch pad.
These
80 locations of RAM are widely used for the purpose of storing
data and parameters by 8051 programmers.
7F
Scratch pad RAM
30
2F
Bit-Addressable RAM
20
1F
Register Bank 3
18
17
Register Bank 2
10
0F
Register Bank 1 (stack)
08
07
Register Bank 0
00
The 32 bytes of RAM which is set aside for the register banks and
stack is divided into 4 banks of registers in which each bank has 8
registers, R0 – R7. RAM locations from 0 to 7 are set aside for bank 0
of R0 – R7
R7 7 R7 7 R7 7 R7 7
R6 6 R6 6 R6 6 R6 6
R5 5 R5 5 R5 5 R5 5
R4 4 R4 4 R4 4 R4 4
R3 3 R3 3 R3 3 R3 3
R2 2 R2 2 R2 2 R2 2
R1 1 R1 1 R1 1 R1 1
R0 0 R0 0 R0 0 R0 0
STACK IN THE 8051
The stack is a section of RAM used by the CPU to store information
temporarily. This information could be data or an address. The CPU
needs this storage area since there are only a limited number of
registers. The register used to access the stack is called the SP
(stack pointer) register. The stack pointer in the 8051 is only 8 bits
wide i.e. it can take values of 00 to FFH. When the 8051 is powered
up, the SP register contains value 07 which implies that RAM location
08 is the first location being used for the stack by the 8051.
In the 8051 the stack pointer (SP) is pointing to the last used location
of the stack. As data is pushed onto the stack, the stack pointer (SP)
is incremented by one and the contents of the register are saved on
the stack. To push the registers onto the stack, RAM addresses are
used.
Popping the contents of the stack back into a given register is the
opposite process of pushing. With every pop, the top byte of the stack
is copied to the register specified by the instruction and the stack
pointer is decremented once.
ADDRESSING MODES:
The addressing modes in the microcontroller instruction set are as
follows:
1. DIRECT ADDRESSING
2. INDIRECT ADDRESSING
3. REGISTER INSTRUCTIONS
4. REGISTER-SPECIFIC INSTRUCTIONS
MOV A, #100
Loads the Accumulator with the decimal number 100. The same
number could be specified in hex digits as 64H.
6. INDEXED ADDRESSING