Reference: The 8051 Microcontroller: Architecture, Programming & Applications by Kenneth J. Ayala
Reference: The 8051 Microcontroller: Architecture, Programming & Applications by Kenneth J. Ayala
External Interrupt
Interrupts control ROM for
On-Chip Timer/
program
RAM counters
code
CPU
EA = 1 EA = 0
4K 0000 64K 1000
7F 80
Internal
data
RAM
00 0100
The 8051 architecture
The on-chip RAM contains a rich arrangement of general purpose storage, bit addressable
storage, register banks, and special function registers.
The internal memory space is divided between register banks (00H-1FH), bit-addressable
RAM (20H-2FH), general purpose RAM (30H-7FH) and special function registers (80H-
FFH).
FF
Special Function Registers
80 Direct addressing Only
7F Direct and Indirect
30 Addressing
2F
Bit Addressable
20
1F
General Purpose Register
4 Register Banks
00
The 8051 architecture
Port 1: Port 1 is an 8-bit bidirectional I/O port. No alternate functions are assigned for Port
1 pins , thus they are used solely for interfacing to external devices.
Port 2: Port 2 is an 8-bit dual purpose port serving as general I/O port , or as the high byte
of the address bus for designs with external memories.
Port 3: Port 3 is an 8-bit bidirectional I/O port. It also serves the functions of various
special features of the 80C51 Family as follows:
P3.0 RXD (Serial input port)
P3.1 TXD (Serial output port)
P3.2 INT0 (External interrupt 0)
P3.3 INT1 (External interrupt 1)
P3.4 T0 (Timer/Counter 0 external input)
P3.5 T1 (Timer/Counter 1 external input)
P3.6 WR (External data memory write strobe)
P3.7 RD (External data memory read strobe)
The 8051 architecture
PSEN: Program Store Enable is the read strobe to external Program Memory. PSEN is not
activated when the device is executing out of internal Program Memory.
EA/VPP: When External Access Enable is held high the CPU executes out of internal
Program Memory. Holding EA low forces the CPU to execute out of external memory
regardless of the Program Counter value. In the EPROM devices, this pin also receives the
programming supply voltage (VPP) during EPROM programming.
The accumulator (A) is the most versatile register and is used for many operations
including addition, subtraction, integer multiplication and division, and Boolean
bit manipulations.
The register A is also used for all data transfers between the 8051 and any external
memory.
The B register is used with the A register for multiplication and division operations
and has no other function than as a location where data may be saved.
The 8051 architecture
Program Counter
Program Counter (PC) indicates where the microcontroller is in its instruction
sequence.
Program instructions bytes are fetched from locations in the memory that are
addressed by the PC.
PC holds the address of the next instruction to be executed.
The PC is automatically incremented after every instruction byte is fetched and may
also be altered by certain instructions.
The PC is the only register that does not have an internal address.
Data Pointer
The Data Pointer (DPTR), used to access external code or data memory, is a 16-bit
register at address 82h (DPL) and 83h (DPH).
The following three instructions write 55h into external RAM location 1000h:
MOV A, #55h
MOV DPTR, #1000h
MOVX @DPTR, A
The 8051 architecture
Carry Flag: CF is dual purpose bit. It is set 1 if there is a carry out of bit 7 during an add or
if there is a borrow into bit 7 during a subtract. CF is also the Boolean Accumulator
serving as a 1-bit register for Boolean operation.
Auxiliary Carry: When adding binary-coded-decimal (BCD) values, the AC flag is set if a
carry was generated out of bit 3 into bit 4.
The 8051 architecture
Stack Pointer
The SP is an 8-bit register at address 81H. It contains the address of the data item currently
on top of the stack. Stack operations include “pushing” data on the stack and “popping” data
off the stack.
When data is to be placed on the stack, the SP increments before storing data on the stack so
that the stack grows up as data is stored. As data is retrieved from the stack, the byte is read
from the stack and then the SP decrements to point to the next available byte of stored data.
The 8051 architecture
Interrupts
An interrupt is the occurrence of a condition – an event – that causes a temporary
suspension of a program while the condition is serviced by another program called
subroutine.
Interrupts may be generated by internal chip operations or provided by external sources. Any
interrupt can cause the 8051 to perform a hardware call to an interrupt handling subroutine
that is located at a predetermined address in program memory.
There are five interrupt sources on the 8051; two external interrupts (INT0 and INT1) at port
pins P3.2 and P3.3, two timer interrupts (Timer flag 0 and Timer flag 1) and one serial port
interrupt (RI or TI).
Programmer is able to alter control bits of Interrupt Enable register (IE), Interrupt Priority
register (IP) and the Timer Control register (TCON).
After the interrupt is handled by the interrupt subroutine, the interrupted program must
resume operation at the instruction where the interrupt took place.
Program resumption is done by storing the interrupted PC address on the stack in RAM
before changing the PC to the interrupt address in ROM. The PC address will be restored
from the stack after an RETI instruction is executed at the end of interrupt subroutine.
The 8051 architecture
Interrupt Enable register (IE)