Professional Documents
Culture Documents
MC Unit 1
MC Unit 1
Program memory:
Internal (Onchip)
Permanent memory
Data memory:
Internal (Onchip)
RAM
128 bytes RAM on chip Internal data memory is access with 8 bit address lines
64 KB Ram offchip External data memory access with 16 bits address bus
Stack Area
The stack area in 8051always can be implemented in the internal data memory. Here the
stack pointer (SP) is an only 8-bit register, because the internal RAM area is only in range
00H to 7FH, and when all register banks are being used, the stack location will be in range
30H to 7FH. So in such a case, the SP will be initialized with 2FH.
The stack pointer SP increases before each PUSH operation and decreases after each pop
instruction.
When the 8051 is reset, the Stack Pointer will point to 07H. It means the location 08H to
7FHcan be used as a stack. We are assuming that the register bank 0 is in use and 20H to
27H are not like bit-addressable area.
We have already discussed that the 8051 microcontroller has the internal program memory.
In this chip, there is EA pin. It indicates the External Access. So by using this pin, we can
check whether the internal program memory is used or not. So when there is a low signal in
this pin, the internal 4K bytes of program memory is not used, but in this situation, it can
access only the ROM.
When we are trying to access the external data memory, then the read RD or write WR will
be the output from 8051. So for reading the data from external sources,
there PSEN (Program Strobe Enable) pin. This is an active low output pin. When this pin is
active low, it indicates that the microcontroller reads from the external ROM. The 16-bit
ROM address will be floated on Port 2 (MS Byte) and Port 0 (LS Byte). The program code is
received on Port 0 pins.
So there is two case of accessing the program memory. The first case is when EA is low, and
the second case is when EA is high. For the low state of EA, it can access the entire external
memory from location 0000H to FFFFH. And in the second case (EA = 1). In this case, the
internal memory is accessed by the address 0000H to 0FFFH. And also the external memory
is accessed from location 1000H to FFFFH.
The external program memory address is always 16-bit address. If the memory is very small
compared to 64KB memory, then also the address will be 16-bit. So when we use the
external memory, we cannot use the Port0 and Port 2 as IO ports. The instruction execution
times are not depending on the on-chip ROM or external EPROMs
So the structure of external program memory interfacing is like below
8051 Interrupts
Reset - 0000H
Reset
Reset is the highest priority interrupt, upon reset 8051 microcontroller start executing
code from 0x0000 address.
8051 has two internal interrupts namely timer0 and timer1. Whenever timer
overflows, timer overflow flags (TF0/TF1) are set. Then the microcontroller jumps to
their vector address to serve the interrupt. For this, global and timer interrupt should
be enabled.
Serial interrupt
8051 has a serial communication port and have related serial interrupt flags (TI/RI).
When the last bit (stop bit) of a byte is transmitted, the TI serial interrupt flag is set,
and when the last bit (stop bit) of the receiving data byte is received, the RI flag gets
set.
Bit 7 – EA: Enable All Bit
Interrupt priority
Priority to the interrupt can be assigned by using the interrupt priority register (IP)
Priority Interrupt source Intr. bit / flag
In the table, interrupts priorities upon reset are shown. As per 8051 interrupt
priorities, the lowest priority interrupts are not served until the microcontroller is
finished with higher priority ones. In a case when two or more interrupts arrive
microcontroller queues them according to priority.
Address is 80H
Construction: Port 0 has a D-type latch, unidirectional buffer, and 2
FETs at each pin. It does not have an internal pull-up resistor. An
external pull-up resistor is needed when Port 0 is defined as an output
port.
Port 0 of the 8051 has two main functions: To be used as a simple
input-output port and to access external memory in conjunction with
Port 2.
it can be used for address/data interfacing for accessing external memory.
It is a bidirectional port
Features of Port 1:
Address is 90H
Construction: Port 1 has one latch, output buffers and input buffers.
It has only one function – to act as an Input-Output port.
Features of Port 2
Address is 10H
Construction: Port 2 has a D type latch, 1 FET, an internal pull-up
resistor, two unidirectional buffers, and a Control Logic block.
Its main functions are kind of similar to those of Port 0. It can be used
as an input-output port. And can access external memory in
conjunction with Port 0.
Features of Port 3
Address is B0H
Construction: The third Port of 8051 has a D-type latch. In addition to
that, it has three unidirectional buffers. A FET with an internal pull-
up resistor. Additionally, it also has a NAND gate connected to the
FET.
Port 3 performs two main functions, as we will see below.
Functions of Port 3
I/O port
Just like Port 2, Port 3 can function as an input-output port.
Alternate SFR function
The input to SFR 1, we get the output of latch as 1, which turns on the NAND gate,
and depending on the value of ‘Alternate Output Pin,’ FET will be wither
ON/OFF.
RXD: this is used for a serial input port
TXD: this is used for serial output port
INT0: this used for an external interrupt 0
INT1: this used for external interrupt 1
T0: Timer 0 external input
T1: Timer 1 external input
WR: external data memory write strobe
RD: external data memory Read strobe
The following table describes the function of each bit in the SCON
Register.
Bit Symbol De
5 SM2 Multiproc
4 REN Recei
3 TB8 Trans
2 RB8 Rec
1 TI Transmi
0 RI Receive
The Serial Port Mode Selection Bits (SM0 and SM1) determine the mode
of UART and also the baud rate. The following table gives an overview of
how the Serial Port Mode Selection Bits can be used to configure Serial
Port (UART) of 8051.